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 $content;
add_filter('the_excerpt_rss', 'removeRssPrivatePost');
add_filter('the_content_feed', 'removeRssPrivatePost');
  • Are you using a pre_get_posts filter by any chance?
    – Tom J Nowell
    Commented Mar 4, 2020 at 12:15

3 Answers 3


The 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' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.