WordPress – allow password protected content in search results

Source: https://wordpress.org/support/topic/how-to-allow-password-protected-content-in-search-results

SOLUTION:

Add this code to your functions.php file and you will get it to work.

add_filter( 'posts_search', 'include_password_posts_in_search' );
function include_password_posts_in_search( $search ) {
  global $wpdb;
  $pattern = " AND ({$wpdb->prefix}posts.post_password = '')";
  $search = str_replace( $pattern, '', $search );
  return $search;
}

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *