• Resolved Jos Velasco

    (@josvelasco)


    I want to automatically hide categories with less than x published posts from the function the_category().

    For some kind of sites I don’t see the point of showing a category link if it only has a couple of posts, but since eventually the category will have more I want to assign it from the beginning.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this code snippet:

    add_filter( 'get_the_categories', 'min_post_count_for_category_list' );
    function min_post_count_for_category_list( $list ) {
    	foreach( $list as $k => $term_obj ) {
    		if ( $term_obj->count < 3 )
    			unset( $list[ $k ] );
    	}
    	return $list;
    }

    Change the 3 as needed.

    Thread Starter Jos Velasco

    (@josvelasco)

    Thank you very much Kailey. It works perfect!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude categories with less than x posts from the_category’ is closed to new replies.