Add has_password and post_password query variables to WP_Query.

* has_password true means posts with passwords, false means posts without.
 * post_password can query for posts with a particular password.

props wonderboymusic, robmiller.
fixes #20308.


git-svn-id: https://develop.svn.wordpress.org/trunk@27395 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin
2014-03-04 07:44:28 +00:00
parent c2dd5d4a75
commit ed43f002b8
2 changed files with 49 additions and 0 deletions

View File

@@ -2702,6 +2702,15 @@ class WP_Query {
$post_type_cap = $post_type;
}
if ( isset( $q['post_password'] ) ) {
$where .= $wpdb->prepare( " AND $wpdb->posts.post_password = %s", $q['post_password'] );
if ( empty( $q['perm'] ) ) {
$q['perm'] = 'readable';
}
} elseif ( isset( $q['has_password'] ) ) {
$where .= sprintf( " AND $wpdb->posts.post_password %s ''", $q['has_password'] ? '!=' : '=' );
}
if ( 'any' == $post_type ) {
$in_search_post_types = get_post_types( array('exclude_from_search' => false) );
if ( empty( $in_search_post_types ) )