我有一个自定义的帖子类型,我想在我的网站上的分类页面上完全显示该帖子类型,而不是网站的常规博客部分。我制作了一个自定义分类法和帖子类型,如下所示:
add_action(\'init\', \'create_post_types\');
function create_post_types() {
register_taxonomy(\'tips-and-tricks-taxonomy\', \'tat\',
array( \'hierarchical\' => true,
\'label\' => \'Destinations (Tips)\',
\'singular_label\' => \'Destination (Tips)\',
\'rewrite\' => array(\'slug\' => \'tips-and-tricks\', \'with_front\' => false),
\'public\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'_builtin\' => true,
\'show_in_nav_menus\' => true));
register_post_type(\'tat\',
array( \'labels\' => array(
\'name\' => __(\'Tips and tricks\'),
\'singular_name\' => __(\'Tip\'),
\'add_new\' => __(\'Add new tip\'),
\'edit_item\' => __(\'Edit tip\'),
\'new_item\' => __(\'New tip\'),
\'view_item\' => __(\'View tip\'),
\'search_items\' => __(\'Search tips and tricks\'),
\'not_found\' => __(\'No tips and tricks found\'),
\'not_found_in_trash\' => __(\'No tips and tricks found in trash\')),
\'has_archive\' => true,
\'public\' => true,
\'supports\' => array(\'title\', \'editor\', \'post-formats\')
));
}
然后,我试图改变如下所示的帖子数量:
function get_all_tat_posts($query)
{
if(!is_admin() && $query->is_main_query() && is_post_type_archive(\'tat\')) {
$query->set(\'posts_per_page\', \'-1\');
}
}
add_action(\'pre_get_posts\', \'get_all_tat_posts\');
调试时,我得到
$query->is_main_query()
和
is_post_type_archive(\'tat\')
两者都返回false。我不知道为什么会出现这个错误,因为我所做的就是导航到该自定义帖子类型的标准类别页面。我不会以任何其他方式更改查询,也不会自己创建查询。
你知道我可能做错了什么吗?