This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Fronted Search Setting options [esclude terms empty]

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Fronted Search Setting options [esclude terms empty]

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10415
    K15Lmk98K15Lmk98
    Participant

    This is an automatic translation

    Good day,

    Frontend Search Settings > Categories & Taxonomy Terms, i added the taxonomy “luoghi” with over 1000 terms. – see screenshot1 –

    It is possible, perhaps through a filter to exclude all empty terms, and leave only those who post?

    Thanks, Claudio_

    #10417
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi Claudio!

    It is actually possible with a filter. Use this code for your case to filter the “luoghi” taxonomy:

    [php]add_filter( ‘asp_fontend_get_taxonomy_terms’, ‘asp_filter_empty_terms’, 1, 3 );

    function asp_filter_empty_terms($terms, $taxonomy, $args) {
    if ( $taxonomy == ‘luoghi’ ) {
    return get_terms($taxonomy, array(
    ‘orderby’ => $args[‘orderby’],
    ‘order’ => $args[‘order’],
    ‘taxonomy’=> $taxonomy,
    ‘hide_empty’ => 1
    ));
    }
    return $terms;
    }[/php]

    #10418
    K15Lmk98K15Lmk98
    Participant

    Hi Ernest,

    Thanks for the filter.
    I just wanted to take the term parent, and I modified the code with ‘parent’ => 0:

    [code]add_filter( ‘asp_fontend_get_taxonomy_terms’, ‘asp_filter_empty_terms’, 1, 3 );
    function asp_filter_empty_terms($terms, $taxonomy, $args) {
    if ( $taxonomy == ‘luoghi’ ) {
    return get_terms($taxonomy, array(
    ‘orderby’ => $args[‘orderby’],
    ‘order’ => $args[‘order’],
    ‘taxonomy’=> $taxonomy,
    ‘parent ‘ => 0,
    ‘hide_empty’ => 1
    ));
    }
    return $terms;
    }[/code]

    But strangely always returns the children – see screnshot –

    You have a solution?

    Thanks, Claudio_

    #10420
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    The parent =>0 parameter works on my test environment, it only displays parent elements, so I don’t know what is wrong.

    If you want, you can provide temporary log-in and FTP and I can take a look.

    #10421
    K15Lmk98K15Lmk98
    Participant

    Hi Ernest,

    in fact it is really strange. I disabled some plugins that could interfere with ASP, but the result does not change.

    I’m developing locally.
    When I publish the site I send accesses.

    Thanks, Claudio_

    #10422
    K15Lmk98K15Lmk98
    Participant

    Hi Ernest,

    This is a machine translation.

    Like I said, it is strange that ‘parent’ => 0 does not work.

    However I want to share the solution I found, if other users had my need.

    [code]add_filter( ‘asp_fontend_get_taxonomy_terms’, ‘asp_filter_empty_terms’, 1, 3 );
    function asp_filter_empty_terms($terms, $taxonomy, $args) {
    if ( $taxonomy == ‘luoghi’ ) {
    $terms = get_terms($taxonomy, array(
    ‘orderby’ => $args[‘orderby’],
    ‘order’ => $args[‘order’],
    ‘taxonomy’=> $taxonomy,
    ‘parent ‘ => 0,
    ‘hide_empty’ => 1
    ));
    foreach ($terms as $key =>$singleTerm) :
    $term = get_term_by(‘id’, $result->term_id, $taxonomy);
    if ( $singleTerm->parent != 0 ) :
    unset($terms[$key]);
    endif;
    endforeach;
    return $terms;
    }

    return $terms;
    }[/code]

    Ticket chiuso. Thanks for the support, Claudio_

    #10425
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Fronted Search Setting options [esclude terms empty]’ is closed to new replies.