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
posts_where
, you're given the query object in the filter so just tell it you don't want passworded posts using$query->set(...
$query->set( 'has_password', false );
did the job. I didn't knew that was possible.