Show Custom Post Types in archive page

pre_get_posts

Change ‘your-custom-post-type’ to your desired custom post type.

You should use $query->is_main_query() to only show these in your archive page (if you don’t, your custom post type posts may show up in your sidebar widget, etc.).

01
02
03
04
05
06
07
08
09
10
function hoge_show_cpt_archives( $query ) {
 
    if( is_tag() &&  $query->is_main_query() ) {
        $query->set( 'post_type', array(
            'post', 'your-custom-post-type'
        ));
        return $query;
    }
}
add_filter( 'pre_get_posts', 'hoge_show_cpt_archives' );