{"id":60586,"date":"2011-10-17T13:01:56","date_gmt":"2011-10-17T17:01:56","guid":{"rendered":"http:\/\/wpmu.org\/?p=60586"},"modified":"2012-10-25T15:59:54","modified_gmt":"2012-10-25T19:59:54","slug":"daily-tip-how-to-show-password-protected-posts-in-wordpress-search-results","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/daily-tip-how-to-show-password-protected-posts-in-wordpress-search-results\/","title":{"rendered":"How to Show Password-Protected Posts in WordPress Search Results"},"content":{"rendered":"<p>By default, WordPress does not include password-protected posts in its search results. Here&#8217;s how you can change this behavior so that users can search through all of your posts.<\/p>\n<p>Add this snippet of code to your theme&#8217;s <i>functions.php<\/i> file:<\/p>\n<p>{code type=php}<br \/>\nadd_filter( &#8216;posts_search&#8217;, &#8216;include_password_posts_in_search&#8217; );<br \/>\nfunction include_password_posts_in_search( $search ) {<br \/>\n\tglobal $wpdb;<br \/>\n\tif( !is_user_logged_in() ) {<br \/>\n\t\t$pattern = &#8221; AND ({$wpdb->prefix}posts.post_password = &#8221;)&#8221;;<br \/>\n\t\t$search = str_replace( $pattern, &#8221;, $search );<br \/>\n\t}<br \/>\n\treturn $search;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>This tip comes to your courtesy of <a href=\"http:\/\/wpsnipp.com\/index.php\/functions-php\/include-password-protected-posts-in-search-results\/\" target=\"_blank\">WPsnipp.com<\/a>. Many thanks to Kevin Chard for posting this code. I tested it and it works as expected. Check out <a href=\"http:\/\/wpsnipp.com\" target=\"_blank\">WPsnipp<\/a> for many more handy code samples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you know that WordPress doesn&#8217;t show password-protected posts in search results? Use this code to get around that.<\/p>\n","protected":false},"author":4099,"featured_media":60593,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[10810,390,186],"tutorials_categories":[],"class_list":["post-60586","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-wordpress-security","tag-code","tag-search"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/60586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/4099"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=60586"}],"version-history":[{"count":0,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/60586\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/60593"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=60586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=60586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=60586"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=60586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}