add_filter( 'posts_search', 'include_password_protected_posts_in_search_result' ); function include_password_protected_posts_in_search_result( $search ) { global $wpdb; if( !is_user_logged_in() ) { $pattern = " AND ({$wpdb->prefix}posts.post_password = '')"; $search = str_replace( $pattern, '', $search ); } return $search; }
当然,这些是写在主题的function.php文件中的。
评论区
发表新的留言
您可以留言提出您的疑问或建议。
您的留言得到回复时,会通过您填写的邮箱提醒您。