Code Element Ca

Add Custom Post Types to Taxonomy Archive Pages

You can add your Custom Post Types to the default ‘category’ and ‘post_tag’ Taxonomy Archive pages in WordPress using the native pre_get_posts action hook. This assumes the default taxonomies are registered to your Custom Post Types.


post-type-one and post-type-two: with your post types

 * Add CPTs to Taxonomy Archive pages
add_filter( 'pre_get_posts', function ($query) {
    if (is_category() || is_tag() && empty($query->query_vars['suppress_filters']) ) {
        $query->set( 'post_type', array('post', 'post-type-one', 'post-type-two'));
        return $query;