0

I'm using a plugin called The Events Calendar, which is creating a custom post type called tribe_events. It also lets me assign categories and add the posts to the main loop. Now I'm trying to get these custom post categories to show up in the standard category filter widget in the sidebar on my blog posts page. What I imagine would look something like this:

Categories:

  • News (14)
  • Special Deals (5)
  • Events (8)

The "News" and "Special Deals" here would be regular blog categories, and "Events" is a category for the custom post type. (I just have one category there, so if it's easier to add the custom posts to a blog category rather than adding the category to the list of categories the widget accepts, that would be just fine.) How do I get the widget in the sidebar to list my "Events" category?

I tried using the function mentioned here (under “Displaying Multiple Post Types on Category Page”) and replaced “movies” with “tribe_events,” but I’m not sure if this would be the right solution or if I did it right, and it doesn’t work for the widget. This is my function:

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if( is_category() ) {
    $post_type = get_query_var('post_type');
    if($post_type)
        $post_type = $post_type;
    else
        $post_type = array('nav_menu_item', 'post', 'tribe_events');
    $query->set('post_type',$post_type);
    return $query;
    }
}
2
  • I guess this function you pasted used for displaying posts from different post type on category page. But you are asking about widget. Default wordpress category widget don't have appropriate hook for your purpose. It uses wp_list_categories function to display a list of categories and this function do not recieve include argument, only exclude.
    – anton
    Apr 25 at 19:58
  • Oh I see. Thanks for explaining this. Would it be best to add a new widget then? Like one that does the same as the regular widget but then also adds my custom post categories? I'm not sure how to get it to do that though.
    – user204381
    Apr 25 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.