Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Hide Empty Categories
- This topic has 5 replies, 2 voices, and was last updated 6 years, 2 months ago by
kubus_IT59.
-
AuthorPosts
-
March 23, 2020 at 11:34 am #26347
kubus_IT59
ParticipantDear support of Ajax Search Pro,
thank you so much for this great plugin, however I need a little support:
– We setup Frontend Search Sttings Category & Taxonomy Terms as a search filter, so the user can search in specific categories
– This works, but in the list there are also categories that are empty (meaning Category A has 15 posts, but Category B has 0 zero posts)This is a problem since, we don’t want categories to show in the filter that have no posts. Except for deleting empty categories manually, is there a way to hide categories automatically, which don’t have posts yet? WordPress has this functionality for their “category cloud”, but it seems it is missing for Ajax Search Pro.
Please let me know if you have further questions. Thank you for your time!
Kind regards
ToniMarch 23, 2020 at 1:52 pm #26352Ernest Marcinko
KeymasterHi,
It is possible, but only via using a custom code at the moment. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter( 'asp_fontend_get_taxonomy_terms', 'asp_filter_empty_terms', 10, 3 ); function asp_filter_empty_terms($terms, $taxonomy, $args) { if ( $taxonomy == 'category' ) { return get_terms($taxonomy, array( 'orderby' => $args['orderby'], 'order' => $args['order'], 'taxonomy'=> $taxonomy, 'hide_empty' => 1 )); } return $terms; }March 23, 2020 at 7:35 pm #26357kubus_IT59
ParticipantDear Ernest Marcinko,
thank you for your fast and also easy Reply. I inserted the custom filter into the functions.php from my child-theme. Please forgive me, I may left out an important Detail: The taxonomy is not the typical “post category” but the Course Category from Learndash. As the Code snipped did not do any Change with $taxonomy == ‘category’ I changed it to == ‘sfwd-courses’- However this still didn’t hide the unused Course category. I packed up a screenshot of my Settings to make it more clear this time. My apologies. Would this still be possible with a filter and the custom taxonomy anyway?
Again, thank you very much.
Kind regards
ToniMarch 23, 2020 at 7:39 pm #26359kubus_IT59
ParticipantOh dear sorry – after rewatching my screenshot I found that I looked in the wrong place for the category Name… I inserted the correct taxonomy == ‘ld_course_category’ and now your filter works like a charm.
Thank you so much for helping me out this quick and sorry for the confusion – it’s getting late and I better shut down the PC, haha. Thank you – ticket can be closed. Great work!
(you may consider this filter Option “hide” for the next update, it works really good. 🙂March 24, 2020 at 9:51 am #26360Ernest Marcinko
KeymasterYou cannot access this content.
March 24, 2020 at 9:58 am #26361kubus_IT59
ParticipantThank you, I will vote it 5 stars as soon as codecanyon works again (trying to vote our last two purchases always gives a 404). I won’t Forget it – thank you again for all your help and this great work.
-
AuthorPosts
- The topic ‘Hide Empty Categories’ is closed to new replies.