Include password protected posts in search results
wordpress snippet
Adding this snippet to the functions.php of your wordpress theme will allow protected posts to show up in search results even when a user is not logged in.
snippet : PHPcopy
add_filter( 'posts_search', 'include_password_posts_in_search' );
function include_password_posts_in_search( $search ) {
global $wpdb;
if( !is_user_logged_in() ) {
$pattern = " AND ({$wpdb->prefix}posts.post_password = '')";
$search = str_replace( $pattern, '', $search );
}
return $search;
}












Pingback: Daily Tip: How to Show Password-Protected Posts in WordPress Search Results