From 5e1193272f62b11cb024c7c022449301e4c39942 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 23 Aug 2016 14:44:19 +0000 Subject: [PATCH] Taxonomy: in `get_terms()`, do not assume that legacy args are being passed when the only params are top-level `meta_*` values. Add keys in `WP_Term_Query::__construct()`. Adds unit tests. Props flixos90, boonebgorges. Fixes #37568. git-svn-id: https://develop.svn.wordpress.org/trunk@38337 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-term-query.php | 4 ++++ tests/phpunit/tests/term/getTerms.php | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 0f9919d90a..f74b31326e 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -208,6 +208,10 @@ class WP_Term_Query { 'cache_domain' => 'core', 'update_term_meta_cache' => true, 'meta_query' => '', + 'meta_key' => '', + 'meta_value' => '', + 'meta_type' => '', + 'meta_compare' => '', ); if ( ! empty( $query ) ) { diff --git a/tests/phpunit/tests/term/getTerms.php b/tests/phpunit/tests/term/getTerms.php index b12877689c..1537370332 100644 --- a/tests/phpunit/tests/term/getTerms.php +++ b/tests/phpunit/tests/term/getTerms.php @@ -11,6 +11,29 @@ class Tests_Term_getTerms extends WP_UnitTestCase { wp_cache_delete( 'last_changed', 'terms' ); } + /** + * @ticket 37568 + */ + public function test_meta_query_args_only() { + register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); + + $term1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); + $term2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); + + $post = self::factory()->post->create( array( 'post_type' => 'post' ) ); + + update_term_meta( $term1, 'somekey', 'thevalue' ); + + wp_set_post_terms( $post, array( $term1, $term2 ), 'wptests_tax' ); + + $found = get_terms( array( + 'meta_key' => 'somekey', + 'meta_value' => 'thevalue', + ) ); + + $this->assertEqualSets( array( $term1 ), wp_list_pluck( $found, 'term_id' ) ); + } + /** * @ticket 35495 */