From 1ff0aebf20dec2a7a5636127e27c9df58a6a084d Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 4 Mar 2014 07:45:14 +0000 Subject: [PATCH] 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 --- wp-includes/query.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wp-includes/query.php b/wp-includes/query.php index eed431d96e..d251ef1763 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -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 ) )