How to let custom post type posts show in standard post archive (like in homepage)?

Hooking the following function with the pre_get_posts filter will add one or more CPTs to the regular archive pages:

function wpse94041_cpts_in_archives( $query ) {
    if( is_category() || is_tag() ) { // more conditional tags possible, if applicable
        $query->set( 'post_type', array(
            'post',
            'tutorial' // add as many CPTs to this array as you like
        ));
    }
    return $query;
}
add_filter( 'pre_get_posts', 'wpse94041_cpts_in_archives' );

Your theme’s functions.php file would be a good fit for the above.

Leave a Comment