mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-14 09:34:41 +00:00
Fix orderby meta handling for WP_Term_Query.
In order to allow meta-related values of `orderby` to be handled properly, the term query's `meta_query` object must run its `get_sql()` method before `orderby` parsing. Fixing this bug required addressing another bug in `WP_Meta_Query`, which caused the table alias index not to be reset when calling `get_sql()` multiple times on the same object. Props littler.chicken. Fixes #37151. git-svn-id: https://develop.svn.wordpress.org/trunk@37860 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -61,4 +61,28 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEqualSets( array( $terms[0], $terms[2] ), $q->terms );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37151
|
||||
*/
|
||||
public function test_order_by_meta_value_num() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
add_term_meta( $terms[0], 'foo', 10 );
|
||||
add_term_meta( $terms[1], 'foo', 1 );
|
||||
add_term_meta( $terms[2], 'foo', 100 );
|
||||
|
||||
$q = new WP_Term_Query( array(
|
||||
'taxonomy' => array( 'wptests_tax' ),
|
||||
'fields' => 'ids',
|
||||
'hide_empty' => false,
|
||||
'meta_key' => 'foo',
|
||||
'orderby' => 'meta_value_num',
|
||||
) );
|
||||
|
||||
$found = array_map( 'intval', $q->terms );
|
||||
$this->assertSame( array( $terms[1], $terms[0], $terms[2] ), $found );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user