I have CPT and Taxonomy (code below). When viewing taxonomy term archive page, it's empty. WordPress doesn't know it has include my custom post type to WP_Query. Am I doing something wrong?
function register_cpt() {
// POST TYPE
$args = array(
'label' => 'Photogallery',
'supports' => array( 'title', 'editor',),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'page',
'taxonomies' => array('gallery_cat')
);
register_post_type( 'photogallery', $args );
// TAXONOMY
$args = array(
'label' => 'Photogallery categories',
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
);
register_taxonomy( 'gallery_cat', 'photogallery', $args );
// CONNECTING ...
register_taxonomy_for_object_type( 'gallery_cat', 'photogallery' );
}
add_action( 'init', 'register_cpt');
When visiting example.com/gallery_cat/cat-1, it's empty. But there is one item with this term in back-end.
When I check main query, its SQL is this:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (12) )
AND wp_posts.post_type IN ('post', 'page', 'attachment') // !!!!!!!
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_author = 1
AND wp_posts.post_status = 'private')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 10
As clearly seen, my custom post type "photogallery" is not included.
What am I doing wrong? Is there some misconfiguration in my code?