【发布时间】:2019-03-22 15:44:11
【问题描述】:
我有一个 wordpress 存档页面,其中显示了我创建的自定义帖子类型,我实际上希望隐藏它。
我使用插件 CPT UI 来创建帖子类型“事件”
在我的博客上,我有一个标记为“精选”的类别 (website.com/category/featured/),在这个“精选”类别页面上,我显示了一些我不想显示的事件 CPT。
我在我的 functions.php 文件中尝试了以下代码,但没有成功:
add_action( 'pre_get_posts', 'exclude_cpt' );
function exclude_cpt( $query ) {
if ( $query->is_category('featured') ) {
$query->set( 'post_type', array('event') );
}
return $query;
}
想法??
【问题讨论】:
标签: php wordpress custom-post-type archive