Skip to content

Instantly share code, notes, and snippets.

@Quasimo
Created February 17, 2013 03:18
Show Gist options
  • Save Quasimo/4969937 to your computer and use it in GitHub Desktop.
Save Quasimo/4969937 to your computer and use it in GitHub Desktop.
WordPress加密文章可搜索的方法
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment