admin管理员组文章数量:1302545
Private posts are visible only to administrators and editors, but I have found that they are displayed publicly in RSS feeds. How can I remove them from there?
I have this code but it doesn't work:
function removeRssPrivatePost($content)
{
global $post;
if ($post->post_status == 'private') {
return;
}
return $content;
}
add_filter('the_excerpt_rss', 'removeRssPrivatePost');
add_filter('the_content_feed', 'removeRssPrivatePost');
Private posts are visible only to administrators and editors, but I have found that they are displayed publicly in RSS feeds. How can I remove them from there?
I have this code but it doesn't work:
function removeRssPrivatePost($content)
{
global $post;
if ($post->post_status == 'private') {
return;
}
return $content;
}
add_filter('the_excerpt_rss', 'removeRssPrivatePost');
add_filter('the_content_feed', 'removeRssPrivatePost');
Share
Improve this question
edited Mar 4, 2020 at 12:51
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Mar 4, 2020 at 12:02
RafaucauRafaucau
1738 bronze badges
1
|
3 Answers
Reset to default 1The same way you would change which posts WP shows on any other screen, pre_get_posts
! If you ever see WP pull in posts, and want to modify what it fetches from the DB, use the pre_get_posts
filter
E.g. something similar to this:
add_action( 'pre_get_posts', function( \WP_Query $query ) {
if ( !$query->is_feed() ) {
return; // this isn't a feed, abort!
}
$query->set( 'post_status', 'publish' ); // we only want published posts, no drafts or private
} );
WordPress should not display private posts in public RSS feeds, except for those privileged users you mentioned, and even they need to be viewing the feed in a browser where they've logged in to your site. If your WordPress does display private posts in the feed for everybody, there's something wrong; perhaps a misbehaving plugin or theme.
Does your theme have a 'feed-rss.php'?
You can add to the query in there so it only shows certain post status'.
$the_query = new WP_Query( array( 'post_status' => array( 'publish' ) );
本文标签: How to remove private posts from RSS feeds
版权声明:本文标题:How to remove private posts from RSS feeds? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741660561a2391011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
pre_get_posts
filter by any chance? – Tom J Nowell ♦ Commented Mar 4, 2020 at 12:15