Question

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?

Was it helpful?

Solution

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' );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top