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]

This topic contains 6 replies, has 2 voices, and was last updated by

 
Keymaster
5 years, 3 months ago.

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

    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_

    Attachments:
    You must be logged in to view attached files.
    #10417

    Hi Claudio!

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

    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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10418

    Participant

    Hi Ernest,

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

    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;
    }

    But strangely always returns the children – see screnshot –

    You have a solution?

    Thanks, Claudio_

    Attachments:
    You must be logged in to view attached files.
    #10420

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10421

    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

    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.

    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;
    }

    Ticket chiuso. Thanks for the support, Claudio_

    #10425
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Fronted Search Setting options [esclude terms empty]’ is closed to new replies.