Custom post types is a powerful feature in WordPress. Custom post types are content types like page, post or image in WordPress.
By default custom post types do not appear in category or tag archive page. We can add custom types to category archive or tag archive page in wordpress using filter in theme functions.php or plugin file.
We can add custom post type to category or tag archive page using pre_get_posts filter.
function optimum_show_cpt_archives( $query ) {
if( is_category() || is_tag() & & empty($query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array('post', 'nav_menu_item', 'my-custom-post' )); //Replace my-custom-post with your post type
return $query;
}
}
add_filter( 'pre_get_posts', ' optimum_show_cpt_archives ' );
Replace my-custom-post with your custom post type. You can also also use multiple post types, separated with comma.