I’ve registered a custom post type “object” and registered the taxonomy “post_tag” so that these objects can be tagged.
register_taxonomy_for_object_type('post_tag', 'object');
When I visit domain.com/tag/{object-slug}
it does not find any post, although there are.
Here is how my CPT was declared:
register_post_type( 'objet',
array('labels' => array(/* removed for clarity */),
'description' => __( 'blabla' ),
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'menu_position' => 3,
'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png',
'rewrite' => array( 'slug' => 'stock', 'with_front' => false ),
'has_archive' => 'stock',
'capability_type' => 'post',
'taxonomies' => array('post_tag'),
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'sticky')
)
);
Tag and Category archive queries default to querying only the
post
post type, to add your custom post type to those queries, you can use thepre_get_posts
action: