Make WordPress Core


Ignore:
Timestamp:
08/03/2016 01:53:25 PM (10 years ago)
Author:
boonebgorges
Message:

In WP_Term_Query, accept a string value for taxonomy.

Merges [38181] to the 4.6 branch.

Props endocreative.
Props ocean90 for review.
Fixes #37545.

Location:
branches/4.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

  • branches/4.6/tests/phpunit/tests/term/query.php

    r38099 r38182  
    55 */
    66class Tests_Term_Query extends WP_UnitTestCase {
     7        /**
     8         * @ticket 37545
     9         */
     10        public function test_taxonomy_should_accept_single_taxonomy_as_string() {
     11                register_taxonomy( 'wptests_tax_1', 'post' );
     12                register_taxonomy( 'wptests_tax_2', 'post' );
     13
     14                $term_1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
     15                $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) );
     16
     17                $q = new WP_Term_Query( array(
     18                        'taxonomy' => 'wptests_tax_2',
     19                        'fields' => 'ids',
     20                        'hide_empty' => false,
     21                ) );
     22
     23                $this->assertEqualSets( array( $term_2 ), $q->terms );
     24        }
     25
     26        public function test_taxonomy_should_accept_taxonomy_array() {
     27                register_taxonomy( 'wptests_tax_1', 'post' );
     28                register_taxonomy( 'wptests_tax_2', 'post' );
     29
     30                $term_1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
     31                $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) );
     32
     33                $q = new WP_Term_Query( array(
     34                        'taxonomy' => array( 'wptests_tax_2' ),
     35                        'fields' => 'ids',
     36                        'hide_empty' => false,
     37                ) );
     38
     39                $this->assertEqualSets( array( $term_2 ), $q->terms );
     40        }
     41
    742        /**
    843         * @ticket 37074
Note: See TracChangeset for help on using the changeset viewer.