Make WordPress Core


Ignore:
Timestamp:
12/18/2015 05:43:46 PM (11 years ago)
Author:
boonebgorges
Message:

Ensure get_terms() results are unique when using 'meta_query'.

The introduction of 'meta_query' to get_terms() in 4.4 made it possible for
get_terms() to erroneously return duplicate results. To address the issue,
we add the DISTINCT keyword to the SQL query when a 'meta_query' parameter
has been provided.

Props @jadpm.
Fixes #35137.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/getTerms.php

    r35242 r36003  
    15721572
    15731573        /**
     1574         * @ticket 35137
     1575         */
     1576        public function test_meta_query_should_not_return_duplicates() {
     1577                register_taxonomy( 'wptests_tax', 'post' );
     1578                $terms = self::factory()->term->create_many( 1, array( 'taxonomy' => 'wptests_tax' ) );
     1579                add_term_meta( $terms[0], 'foo', 'bar' );
     1580                add_term_meta( $terms[0], 'foo', 'ber' );
     1581
     1582                $found = get_terms( 'wptests_tax', array(
     1583                        'hide_empty' => false,
     1584                        'meta_query' => array(
     1585                                array(
     1586                                        'key' => 'foo',
     1587                                        'value' => 'bur',
     1588                                        'compare' => '!=',
     1589                                ),
     1590                        ),
     1591                        'fields' => 'ids',
     1592                ) );
     1593
     1594                $this->assertEqualSets( array( $terms[0] ), $found );
     1595        }
     1596
     1597        /**
    15741598         * @ticket 14162
    15751599         */
Note: See TracChangeset for help on using the changeset viewer.