How to count custom taxonomy posts in wordpress walker
-
I’ve written a custom walker for my wordpress menu widget. It styles things for bootstrap. I’m trying to add a count next to each category item. I have that working, however I’ve converted to using a custom taxonomy so that the site is easier to use for my users.
Before, I was finding the category count with this function.
//this function adds category counts if the nav menu item is a category
add_filter(‘the_title’, ‘wpse165333_the_title’, 10, 2);
function wpse165333_the_title($title, $post_ID)
{if( ‘nav_menu_item’ == get_post_type($post_ID) )
{if( ‘taxonomy’ == get_post_meta($post_ID, ‘_menu_item_type’, true) && ‘careerstax’ == get_post_meta($post_ID, ‘_menu_item_object’, true) )
{
$category = get_category( get_post_meta($post_ID, ‘_menu_item_object_id’, true) );if(isset($category->count) && $category->count !=”){
$cat_count_display = “<span class=’badge pull-right’>”.$category->count.”</span>”;
$title .= sprintf(‘ %s’, $cat_count_display);
}}
}
return $title;
}I am looking to do the exact same thing but with a custom taxonomy. Does anyone have an idea of how I would do this? I’ve been struggling with this all day and though I would check the forum.
- The topic ‘How to count custom taxonomy posts in wordpress walker’ is closed to new replies.