Remove password protected posts from default RSS feed

I want to remove all password protected posts from the default RSS feed. Unfortunately I was only able to find one code example, but it looks like something is missing.

function rss_filter_protected( $query ) {
    if ( $query->is_feed ) {
        add_filter( 'posts_where', 'rss_filter_password_where' );
    }
    return $query;
}
add_filter( 'pre_get_posts','rss_filter_protected' );

As soon as I save this function the RSS feed displays all post types (attachments, etc.) that are registered to the system instead of only published posts.

If possible I would like to solve this without an additional plugin.

Thanks

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Here’s the filter to exclude password protected posts from the default RSS feed:

function rss_filter_protected( $query ) {
    if ( $query->is_feed ) {
        $query->set( 'has_password', false );
    }
    return $query;
}
add_filter( 'pre_get_posts','rss_filter_protected' );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x