Protected Posts & Site Search Results
-
My understanding is that password-protected posts do not show up in the external site search results. After investigating, I found a code snippet that can be added to the functions.php file that will enable protected posts to show up in those search results. I have added the snippet using the Code Snippets plugin, but it does not seem to work. I am interested in learning about what else I can try.
Here is the code snippet I have tried:
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; }The blog I need help with is: (visible only to logged in users)
-
Hi there,
Can you tell me where you got that code?
I tried it out on both a WordPress.com Business Plan, and on a self-hosted WordPress site, and it doesn’t work on either, which tells me it most likely worked on an older version of the WordPress software, but it no longer works on the most current version.
Unfortunately I’m not a PHP developer, and we don’t provide support for custom code like this on WordPress.com, so I’m not able to help you tweak this so it would work.
I did try searching the WordPress.org forums to see if someone might recently have shared something there, but couldn’t find anything. But if you ask in their advanced forum, someone might be able to help you with the correct code to do this:
https://wordpress.org/support/forum/wp-advanced/
If you don’t have one yet, you’ll need to register a WordPress.org account before you can post there, as your WordPress.com account details won’t work there.
Also note that your Business plan gives you access to both live chat and direct email support. You can reach those at any time by clicking the Help icon that appears bottom-right on all the My Sites pages, or else via the direct link at https://wordpress.com/help/contact
-
I have found the solution (through some e-mailing with WordPress); I’m just going to post this solution here for the sake of anyone who happens upon this forum post in the future:
Jetpack “instant search experience” must be disabled for the code snippet above to work properly.
-
Hi there!
Thanks for letting us know here how you were able to get the code to work. :)
Regards
-
- The topic ‘Protected Posts & Site Search Results’ is closed to new replies.