Adding Categories across posts, and custom post types

By default, only post_type post is shown on category pages. To enable your custom post types, you could hook pre_get_posts, check if it’s a category page, and if so add your post types:

function wpse_category_set_post_types( $query ){
    if( $query->is_category() && $query->is_main_query() ){
        $query->set( 'post_type', array( 'post', 'work', 'services' ) );
    }
}
add_action( 'pre_get_posts', 'wpse_category_set_post_types' );

Leave a Comment