How do I display custom post types through a common taxonomy?

I have posts and I have recipes. Recipes is a custom post type. Recipes make use of the category taxonomy and a newly added recipe has been categorized under beer. When I browse the listing page for the category beer I see all my previous posts categorized under beer while the new recipe does not appear.

How do I link custom post types through their taxonomies? Or, how can I show all post types under a single category?

1 Answer
1

You can use pre_get_posts hook to add your custom post type to the query

function include_recipes( $query ) {
    if ( $query->is_category ) {
        $query->set( 'post_type', array('post','recipes') );
    }
    return $query;
}
add_filter( 'pre_get_posts', 'include_recipes' );

Leave a Comment