wordpress snippets last updated   : April 22, 2014
we now have 631 snippets

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;
}
source →
jqsnipp.com | we just launched jquery snippets website