我有CPT和分类法(代码如下)。查看分类术语存档页面时,该页面为空。WordPress不知道它在WP\\U查询中包含了我的自定义帖子类型。我做错什么了吗?
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\');
访问时
example.com/gallery_cat/cat-1, 它是空的。但有一项在后端使用此术语。
当我检查主查询时,其SQL是:
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
可以清楚地看到,我的自定义帖子类型“photogallery”不包括在内。
What am I doing wrong? 我的代码中是否存在一些错误配置?