WordPress.org

Make WordPress Core

Changeset 38337


Ignore:
Timestamp:
08/23/2016 02:44:19 PM (3 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term-query.php

    r38275 r38337  
    209209            'update_term_meta_cache' => true,
    210210            'meta_query'             => '',
     211            'meta_key'               => '',
     212            'meta_value'             => '',
     213            'meta_type'              => '',
     214            'meta_compare'           => '',
    211215        );
    212216
  • trunk/tests/phpunit/tests/term/getTerms.php

    r37634 r38337  
    1010        _clean_term_filters();
    1111        wp_cache_delete( 'last_changed', 'terms' );
     12    }
     13
     14    /**
     15     * @ticket 37568
     16     */
     17    public function test_meta_query_args_only() {
     18        register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
     19
     20        $term1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     21        $term2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     22
     23        $post = self::factory()->post->create( array( 'post_type' => 'post' ) );
     24
     25        update_term_meta( $term1, 'somekey', 'thevalue' );
     26
     27        wp_set_post_terms( $post, array( $term1, $term2 ), 'wptests_tax' );
     28
     29        $found = get_terms( array(
     30            'meta_key' => 'somekey',
     31            'meta_value' => 'thevalue',
     32        ) );
     33
     34        $this->assertEqualSets( array( $term1 ), wp_list_pluck( $found, 'term_id' ) );
    1235    }
    1336
Note: See TracChangeset for help on using the changeset viewer.