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

Hide Empty Categories

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26347
    kubus_IT59kubus_IT59
    Participant

    Dear 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
    Toni

    #26352
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    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;
    }
    #26357
    kubus_IT59kubus_IT59
    Participant

    Dear 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
    Toni

    #26359
    kubus_IT59kubus_IT59
    Participant

    Oh 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. 🙂

    #26360
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #26361
    kubus_IT59kubus_IT59
    Participant

    Thank 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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Hide Empty Categories’ is closed to new replies.