Make WordPress Core

Ticket #44221: 44221.diff

File 44221.diff, 1.7 KB (added by dlh, 8 years ago)
  • src/wp-includes/class-wp-term-query.php

    diff --git src/wp-includes/class-wp-term-query.php src/wp-includes/class-wp-term-query.php
    index 9da5a20f32..25f8ede047 100644
    class WP_Term_Query {  
    677677                $cache_key    = "get_terms:$key:$last_changed";
    678678                $cache        = wp_cache_get( $cache_key, 'terms' );
    679679                if ( false !== $cache ) {
    680                         if ( 'all' === $_fields ) {
     680                        if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) {
    681681                                $cache = $this->populate_terms( $cache );
    682682                        }
    683683
  • tests/phpunit/tests/term/query.php

    diff --git tests/phpunit/tests/term/query.php tests/phpunit/tests/term/query.php
    index 39496b16cb..660de46e1b 100644
    class Tests_Term_Query extends WP_UnitTestCase {  
    318318                }
    319319        }
    320320
     321        public function test_all_with_object_id_should_return_term_objects() {
     322                register_taxonomy( 'wptests_tax_1', 'post' );
     323                $posts = self::factory()->post->create_many( 2 );
     324                $t     = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
     325
     326                foreach ( $posts as $p ) {
     327                        wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' );
     328                }
     329
     330                $query = new WP_Term_Query();
     331                $args = array(
     332                        'taxonomy'   => 'wptests_tax_1',
     333                        'object_ids' => $posts,
     334                        'fields'     => 'all_with_object_id',
     335                );
     336
     337                $terms = $query->query( $args );
     338                $this->assertNotEmpty( $terms );
     339                foreach ( $terms as $term ) {
     340                        $this->assertInstanceOf( 'WP_Term', $term );
     341                }
     342
     343                // Run again to check the cached response.
     344                $terms = $query->query( $args );
     345                $this->assertNotEmpty( $terms );
     346                foreach ( $terms as $term ) {
     347                        $this->assertInstanceOf( 'WP_Term', $term );
     348                }
     349        }
     350
    321351        /**
    322352         * @ticket 37198
    323353         * @group cache