Bug in query creation for the status (if many)
|Reported by:||asakurayoh||Owned by:||wonderboymusic|
The creation of the "where" for the status is buggy in wp-includes/query.php.
I was trying to get publish post and private post as describe in the doc (with a user not admin, but with the good capabilities):
Show posts if user has the appropriate capability:
Display published and private posts, if the user has the appropriate capability:
$query = new WP_Query( array( 'post_status' => array( 'publish', 'private' ), 'perm' => 'readable' ) );
that was not working so I debug it and the resulting where for the query was a lot strange:
AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND (wp_posts.post_author = 2 AND (wp_posts.post_status = 'private'))
If you read it, it mean that a post need to have 2 status at the same time...
I found the place to change it in wp-includes/query.php (~line 2501):
foreach ( $statuswheres as $statuswhere ) $where .= " AND $statuswhere";
$where_status = implode(' OR ', $statuswheres); if(!empty($where_status)) $where .= " AND ($where_status)";
That all! The query is then more logic AND working:
AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish') OR (wp_posts.post_author = 2 AND (wp_posts.post_status = 'private')))
If someone can create the patch, as I know more git than svn... Wordpress on github, with pull-request, would be so more easy...