[wp-trac] [WordPress Trac] #37378: 4.6 breaks tax query alterations (i.e. INNER_JOIN)

WordPress Trac noreply at wordpress.org
Mon Jul 18 11:49:06 UTC 2016


#37378: 4.6 breaks tax query alterations (i.e. INNER_JOIN)
--------------------------+-----------------------
 Reporter:  nimmolo       |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  4.6
Component:  Taxonomy      |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  2nd-opinion   |     Focuses:
--------------------------+-----------------------
Changes (by ocean90):

 * status:  closed => reopened
 * component:  Query => Taxonomy
 * milestone:  Awaiting Review => 4.6
 * keywords:   => 2nd-opinion
 * resolution:  invalid =>


Old description:

> It seems altering the tax query $pieces['join'] or $pieces['orderby'] is
> breaking the query.
>
> The following function is from repository plugin
> [https://wordpress.org/plugins/simple-taxonomy-ordering/ Simple Taxonomy
> Ordering]. The plugin function works in 4.5.3., no errors.
>
> {{{#!php
> <?php
> /*
> *       Re-Order the taxonomies based on the tax_position value
> *       @since 0.1
> */
> public function yikes_alter_tax_order( $pieces, $taxonomies, $args ) {
>         foreach( $taxonomies as $taxonomy ) {
>                 // confirm the tax is set to hierarchical -- else do not
> allow sorting
>                 if( $this->yikes_is_taxonomy_position_enabled( $taxonomy
> ) ) {
>                         global $wpdb;
>                         $pieces['join'] .= " INNER JOIN $wpdb->termmeta
> AS term_meta ON t.term_id = term_meta.term_id";
>                         $pieces['orderby'] = "ORDER BY
> term_meta.meta_value";
>                 }
>         }
>         return $pieces;
> }
>
> }}}
>
> Throws this error message:
>

> `WordPress database error  You have an error in your SQL syntax; check
> the manual that corresponds to your MySQL server version for the right
> syntax to use near 'ORDER BY term_meta.meta_value ASC' at line 1 for
> query SELECT t.*, tt.* FROM wp_fv47w7_terms AS t INNER JOIN
> wp_fv47w7_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN
> wp_fv47w7_termmeta AS term_meta ON t.term_id = term_meta.term_id WHERE
> tt.taxonomy IN ('category') ORDER BY ORDER BY term_meta.meta_value ASC
> made by WP_List_Table->display,
> WP_Terms_List_Table->display_rows_or_placeholder, get_terms,
> WP_Term_Query->query, WP_Term_Query->get_terms`
>
> Is the syntax in fact incorrect?
>
> I'm not great with query syntax, but if incorrect it seems it would have
> thrown the error in WP 4.5.3

New description:

 It seems altering the tax query `$pieces['join']` or `$pieces['orderby']`
 is breaking the query.

 The following function is from repository plugin
 [https://wordpress.org/plugins/simple-taxonomy-ordering/ Simple Taxonomy
 Ordering]. The plugin function works in 4.5.3., no errors.

 {{{#!php
 <?php
 /*
 *       Re-Order the taxonomies based on the tax_position value
 *       @since 0.1
 */
 public function yikes_alter_tax_order( $pieces, $taxonomies, $args ) {
         foreach( $taxonomies as $taxonomy ) {
                 // confirm the tax is set to hierarchical -- else do not
 allow sorting
                 if( $this->yikes_is_taxonomy_position_enabled( $taxonomy )
 ) {
                         global $wpdb;
                         $pieces['join'] .= " INNER JOIN $wpdb->termmeta AS
 term_meta ON t.term_id = term_meta.term_id";
                         $pieces['orderby'] = "ORDER BY
 term_meta.meta_value";
                 }
         }
         return $pieces;
 }

 }}}

 Throws this error message:


 `WordPress database error  You have an error in your SQL syntax; check the
 manual that corresponds to your MySQL server version for the right syntax
 to use near 'ORDER BY term_meta.meta_value ASC' at line 1 for query SELECT
 t.*, tt.* FROM wp_fv47w7_terms AS t INNER JOIN wp_fv47w7_term_taxonomy AS
 tt ON t.term_id = tt.term_id INNER JOIN wp_fv47w7_termmeta AS term_meta ON
 t.term_id = term_meta.term_id WHERE tt.taxonomy IN ('category') ORDER BY
 ORDER BY term_meta.meta_value ASC made by WP_List_Table->display,
 WP_Terms_List_Table->display_rows_or_placeholder, get_terms,
 WP_Term_Query->query, WP_Term_Query->get_terms`

 Is the syntax in fact incorrect?

 I'm not great with query syntax, but if incorrect it seems it would have
 thrown the error in WP 4.5.3

--

Comment:

 With the new `WP_Term_Query` class the `ORDER BY` keyword is added
 automatically: [source:/trunk/src/wp-includes/class-wp-term-
 query.php?marks=605,621,624#L572]

 This wasn't the case before: [source:/tags/4.5.3/src/wp-
 includes/taxonomy.php?marks=1512-1535,1598,1604,1612#L1589]. See also the
 meta handling which is now in `WP_Term_Query::parse_orderby_meta()`.

 @boonebgorges Should we strip any existing keywords before adding our own?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37378#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list