在我的网站上,我根据以下类别进行了一些编码in_category(\'featured\')
做点什么。现在,这只适用于职位。以及与featured
类别也与其他类别关联。因为它只与featured
类别以特殊设计显示,就是这样。
现在我知道这个问题在这里已经讨论过很多次了,但并不完全是我想要的。因此,在降级这个问题之前,请将其适当地红色化。
在这个帖子里is there a quick way to hide category from everywhere? 以下函数用于排除某些类别,但我不想排除它,我只想隐藏它。
add_action(\'pre_get_posts\', \'wpa_31553\' );
function wpa_31553( $wp_query ) {
//$wp_query is passed by reference. we don\'t need to return anything. whatever changes made inside this function will automatically effect the global variable
$excluded = array(272); //made it an array in case you need to exclude more than one
// only exclude on the front end
if( !is_admin() ) {
$wp_query->set(\'category__not_in\', $excluded);
}
}
例如,假设一篇帖子与featured
类别,也与Work
类别现在作为featured
是按字母顺序排在第一位的面包屑(使用Yoast SEO面包屑)将显示featured
作为类别名称,帖子元(显示在帖子下方)将显示两个类别名称,即。featured
和work
.这就是为什么我想隐藏featured
完全分类,这样前端用户就不会知道featured
类别存在。它不会出现在面包屑、贴子元、贴子类别列表中,也不会出现在何处。它将保持隐藏状态,但在后端代码中,当我尝试对其中的那些帖子执行特定操作时,它仍将起作用featured
类别使用in_category(\'featured\')
.
是否有人知道如何获得此类别隐藏(不排除)功能。