[wp-trac] [WordPress Trac] #25629: Taxonomy get_sql() generate incorrect query
WordPress Trac
noreply at wordpress.org
Fri Oct 18 14:32:59 UTC 2013
#25629: Taxonomy get_sql() generate incorrect query
-------------------------+-------------------------------------------------
Reporter: xavismeh | Owner:
Type: defect | Status: new
(bug) | Milestone: Awaiting Review
Priority: normal | Version: 3.5.1
Component: Taxonomy | Keywords: has-patch dev-feedback needs-
Severity: critical | testing
-------------------------+-------------------------------------------------
Hello,
I'm using Wordpress 3.5.1 and came to an incorrectly generated query when
trying to display the pages list causing no display of any page. WP is
configured to run multiple sites and I'm using the administrator account.
Here is the incorrect generated query :
{{{
SELECT prefix_posts.* FROM prefix_posts WHERE 1=1 AND 0 = 1 AND
prefix_posts.post_type = 'page' AND (prefix_posts.post_status = 'publish'
OR prefix_posts.post_status = 'future' OR prefix_posts.post_status =
'draft' OR prefix_posts.post_status = 'pending' OR
prefix_posts.post_status = 'private') GROUP BY prefix_posts.ID ORDER BY
prefix_posts.menu_order,prefix_posts.post_title asc
}}}
As you can see, the "WHERE 0=1" cant' return anything. I bypassed this
error using the diff below. Note that as of today, the error still exists
in the svn trunk.
{{{
Index: wp-includes/taxonomy.php
===================================================================
--- wp-includes/taxonomy.php (revision 148746)
+++ wp-includes/taxonomy.php (working copy)
@@ -678,11 +678,27 @@
if ( empty( $terms ) ) {
if ( 'OR' == $this->relation ) {
- if ( ( $index + 1 ===
$count ) && empty( $where ) )
- return
self::$no_results;
+ if ( ( $index + 1 ===
$count ) && empty( $where ) ) {
+ if (!empty($where)) {
+ $where = ' AND (' . implode("
$this->relation ", $where) . ')';
+ }
+ else {
+ $where = '';
+ }
+
+ return array('join' => $join, 'where' =>
$where);
+ }
+
continue;
} else {
- return self::$no_results;
+ if (!empty($where)) {
+ $where = ' AND (' . implode(" $this->relation
", $where) . ')';
+ }
+ else {
+ $where = '';
+ }
+
+ return array('join' => $join, 'where' => $where);
}
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25629>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list