Tags shared by CPTs and standard posts return only the latter, and
topics
archives or tag archives with only CPTs assigned return empty.
As for the tag archives, that’s a default behavior in WordPress core, i.e. tag (post_tag
taxonomy) and category (category
taxonomy) archives will only query posts where the type is post
.
However, the pre_get_posts
hook can be used to include custom post types in the main posts query on tag and category archives, like so for tag archives and your CPTs:
add_action( 'pre_get_posts', function ( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_tag() ) {
$query->set( 'post_type', array( 'post', 'mama', 'webinar', 'video',
'discount', 'faq' ) );
}
} );
As for the topics
archives, they’re empty because you set exclude_from_search
to true
, which not only excludes the post type from search results, but also taxonomy/term archives.
Excerpt from the documentation: (formatting by me)
Note: If you want to show the posts’s list that are associated to taxonomy’s terms, you must set
exclude_from_search
tofalse
(ie : for callsite_domain/?taxonomy_slug=term_slug
orsite_domain/taxonomy_slug/term_slug
). If you set totrue
, on the taxonomy page (ex:taxonomy.php
) WordPress will not find your posts and/or pagination will make 404 error…
So to fix the topics
archives, either set the exclude_from_search
to false
, or you could use the pre_get_posts
hook like the example for tag archives:
add_action( 'pre_get_posts', function ( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_tax( 'topics' ) ) {
$query->set( 'post_type', array( 'discount', 'video', 'webinar' ) );
}
} );