[wp-trac] [WordPress Trac] #25523: Bug in query creation for the status (if many)
WordPress Trac
noreply at wordpress.org
Mon Oct 7 14:56:05 UTC 2013
#25523: Bug in query creation for the status (if many)
--------------------------+-----------------------------
Reporter: asakurayoh | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: trunk
Severity: major | Keywords: needs-patch
--------------------------+-----------------------------
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):
http://codex.wordpress.org/Class_Reference/WP_Query
----
'''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";
}}}
for:
{{{
$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...
Thanks.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25523>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list