我正在尝试注册一个新的帖子类型,以便在搜索中隐藏帖子,但仍然允许通过url查看帖子。
function reg_ghost_status(){
register_post_status( \'ghosted\', array(
\'label\' => \'Ghost Post\',
\'publicly_queryable\' => false,
\'exclude_from_search\' => true,
\'public\' => true, //on false hides everywhere
\'show_in_admin_all_list\' => true,
\'show_in_admin_status_list\' => true,
) );
}
add_action( \'init\', \'reg_ghost_status\' );
我无法完成这项工作,尝试了各种组合。似乎因为它是“公共的”,所以无论什么设置,它都会显示在任何地方。因此,我尝试使用pre\\u set\\u查询,但我不知道如何使用exclude而不是include by post\\u status。
function sxcsexclude_ghost_from_search($query) {
if ( $query->is_single ) {
$query->set(\'perm\', \'readable\');
$query->set(\'post_status\', array( \'publish\', \'draft\', \'ghosted\', \'future\' ));
return $query;
}
}
add_action( \'pre_get_posts\', \'11111exclude_ghost_from_search\' );
有人能告诉我为什么register\\u post\\u状态不起作用吗。
谢谢