When your custom post type (CPT) does not show up in your tag archive

When your custom post types (CPT) are not showing up in your regular tag archives in Elementor.

The Situation

I created a Custom Post Type, which, from here I will call CPT, using the CPT UI plugin. Please note that in this case it doesn’t matter which plugin you use to create that CPT. It could also have been Pods or Toolset.

Archive was set to “true”.

Connected taxonomies I set to include the default WordPress categories and tags:

Screenshot of CPT UI setting for Taxonomies, set to include default categories and tags.

… and then my tag links just didn’t show the tutorials with the tags. They only showed regular posts.

Steps to solve it

  1. Add the code snippet below to your functions.php. Either in a child theme, or if you don’t have a child theme, I recommend you install a free plugin called Code Snippets, and put it there.
  2. Where the code says custom_post_type, replace that with the name of your own custom post type.
add_action( 'pre_get_posts', function ( $q )
{
    if (  !is_admin() // Only target front end queries
          && $q->is_main_query() // Only target the main query
          && $q->is_tag()        // Only target tag archives
    ) {
        $q->set( 'post_type', ['post', 'custom_post_type'] ); // Change 'custom_post_type' to YOUR Custom Post Type
                                                              // You can add multiple CPT's separated by comma's
    }
});

Helpful resources

It was this documentation page of the Pods plugin, where I found the code snippet. They go a bit more in-depth about it, than I do here.