我想删除所有帖子类型为nf_sub
从出现在任何RSS提要(包括评论提要)中,我该如何做到这一点?
从所有RSS提要中删除某个帖子类型
2 个回复
SO网友:luke
将此粘贴到functions.php
或将其保留在自定义插件中。代替your-cpt
一串
/**
* Filter the feed, exclude specific custom post type
*
* @param WP_Query object $query
* @return void
*/
function wpse_191804_pre_get_posts( $query )
{
// only for feeds
if( !$query->is_feed || !$query->is_main_query() )
return query;
$exclude = \'your-cpt\';
$post_types = $query->get(\'post_type\');
if (($key = array_search($exclude, $post_types)) !== false)
unset($post_types[$key]);
$query->set( \'post_type\', $post_types );
return $query;
}
add_action( \'pre_get_posts\', \'wpse_191804_pre_get_posts\' );
SO网友:Mark Kaplun
默认情况下,RSS提要中只显示实际帖子。如果你有其他类型的帖子,这表明你有一个插件负责这样做,你需要咨询它的作者,以了解如何禁止包含特定的帖子类型。
结束