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.

Built from https://develop.svn.wordpress.org/trunk@27395


git-svn-id: http://core.svn.wordpress.org/trunk@27243 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-03-04 07:45:14 +00:00
parent 5468377d3e
commit 1ff0aebf20
1 changed files with 9 additions and 0 deletions

View File

@ -2702,6 +2702,15 @@ class WP_Query {
$post_type_cap = $post_type; $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 ) { if ( 'any' == $post_type ) {
$in_search_post_types = get_post_types( array('exclude_from_search' => false) ); $in_search_post_types = get_post_types( array('exclude_from_search' => false) );
if ( empty( $in_search_post_types ) ) if ( empty( $in_search_post_types ) )