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 Ernest Marcinko 6 years, 11 months ago.
- AuthorPosts
- October 10, 2016 at 11:53 am #10415
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.October 10, 2016 at 12:04 pm #10417Hi Claudio!
It is actually possible with a filter. Use this code for your case to filter the “luoghi” taxonomy:
Best,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; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 10, 2016 at 12:31 pm #10418Hi 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.October 10, 2016 at 12:42 pm #10420Hi,
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 :)
October 10, 2016 at 1:10 pm #10421Hi 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_
October 10, 2016 at 4:43 pm #10422Hi 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_
October 11, 2016 at 8:15 am #10425You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
The topic ‘Fronted Search Setting options [esclude terms empty]’ is closed to new replies.