diff --git src/wp-includes/class-wp-meta-query.php src/wp-includes/class-wp-meta-query.php
index affb83a..4019912 100644
|
|
class WP_Meta_Query { |
327 | 327 | return false; |
328 | 328 | } |
329 | 329 | |
| 330 | $this->table_aliases = array(); |
| 331 | |
330 | 332 | $this->meta_table = $meta_table; |
331 | 333 | $this->meta_id_column = sanitize_key( $type . '_id' ); |
332 | 334 | |
diff --git src/wp-includes/class-wp-term-query.php src/wp-includes/class-wp-term-query.php
index 924a1e8..dd42166 100644
|
|
class WP_Term_Query { |
814 | 814 | protected function parse_orderby_meta( $orderby_raw ) { |
815 | 815 | $orderby = ''; |
816 | 816 | |
| 817 | // Tell the meta query to generate its SQL, so we have access to table aliases. |
| 818 | $this->meta_query->get_sql( 'term', 't', 'term_id' ); |
817 | 819 | $meta_clauses = $this->meta_query->get_clauses(); |
818 | 820 | if ( ! $meta_clauses || ! $orderby_raw ) { |
819 | 821 | return $orderby; |
diff --git tests/phpunit/tests/term/query.php tests/phpunit/tests/term/query.php
index d1f875b..37dbe48 100644
|
|
class Tests_Term_Query extends WP_UnitTestCase { |
61 | 61 | |
62 | 62 | $this->assertEqualSets( array( $terms[0], $terms[2] ), $q->terms ); |
63 | 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @ticket 37151 |
| 67 | */ |
| 68 | public function test_order_by_meta_value_num() { |
| 69 | register_taxonomy( 'wptests_tax', 'post' ); |
| 70 | |
| 71 | $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); |
| 72 | |
| 73 | add_term_meta( $terms[0], 'foo', 10 ); |
| 74 | add_term_meta( $terms[1], 'foo', 1 ); |
| 75 | add_term_meta( $terms[2], 'foo', 100 ); |
| 76 | |
| 77 | $q = new WP_Term_Query( array( |
| 78 | 'taxonomy' => array( 'wptests_tax' ), |
| 79 | 'fields' => 'ids', |
| 80 | 'hide_empty' => false, |
| 81 | 'meta_key' => 'foo', |
| 82 | 'orderby' => 'meta_value_num', |
| 83 | ) ); |
| 84 | |
| 85 | $found = array_map( 'intval', $q->terms ); |
| 86 | $this->assertSame( array( $terms[1], $terms[0], $terms[2] ), $found ); |
| 87 | } |
64 | 88 | } |