Wordpress | Add Custom post types to tags and categories archives

// Add Custom post types to tags and categories archives
function add_cpts_to_archive_page( $query ) {
  if( (is_category() || is_tag()) && $query->is_archive() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'custom-post-type-1', 'custom-post-type-2'
        ));
    }
    return $query;
}
add_filter( 'pre_get_posts', 'add_cpts_to_archive_page' );

 

My website may contain fan art inspired by existing characters from movies or tv shows, I dont own any rights. Any copyright owner willing to remove those fan arts can contact me here. This is a personal portfolio, the sole use of cookies are for analysing my traffic through Google Analytics, if you're ok with that please accept this terms by closing this disclaimer.