Make WordPress Core

Changeset 48663


Ignore:
Timestamp:
07/28/2020 02:21:54 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Taxonomy: Ensure the child_of argument of get_terms() works as expected with 'fields' => 'id=>name' or 'id=>slug'.

Props Howdy_McGee, deepaklalwani, planvova.
Fixes #46768.

Location:
trunk
Files:
2 edited

Legend:

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

    r48586 r48663  
    621621                                break;
    622622                        case 'id=>name':
    623                                 $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' );
     623                                $selects = array( 't.term_id', 't.name', 'tt.parent', 'tt.count', 'tt.taxonomy' );
    624624                                break;
    625625                        case 'id=>slug':
    626                                 $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' );
     626                                $selects = array( 't.term_id', 't.slug', 'tt.parent', 'tt.count', 'tt.taxonomy' );
    627627                                break;
    628628                }
  • trunk/tests/phpunit/tests/term/getTerms.php

    r47122 r48663  
    721721
    722722        /**
     723         * @ticket 46768
     724         */
     725        function test_get_terms_child_of_fields_id_name() {
     726                $parent = self::factory()->category->create();
     727                $child  = self::factory()->category->create(
     728                        array(
     729                                'parent' => $parent,
     730                                'slug'   => 'test-1',
     731                                'name'   => 'Test 1',
     732                        )
     733                );
     734                $child2 = self::factory()->category->create(
     735                        array(
     736                                'parent' => $parent,
     737                                'slug'   => 'test-2',
     738                                'name'   => 'Test 2',
     739                        )
     740                );
     741
     742                $terms = get_terms(
     743                        'category',
     744                        array(
     745                                'child_of'   => $parent,
     746                                'hide_empty' => false,
     747                                'fields'     => 'id=>name',
     748                        )
     749                );
     750
     751                $this->assertEquals(
     752                        array(
     753                                $child  => 'Test 1',
     754                                $child2 => 'Test 2',
     755                        ),
     756                        $terms
     757                );
     758
     759        }
     760
     761        /**
     762         * @ticket 46768
     763         */
     764        function test_get_terms_child_of_fields_id_slug() {
     765                $parent = self::factory()->category->create();
     766                $child  = self::factory()->category->create(
     767                        array(
     768                                'parent' => $parent,
     769                                'slug'   => 'test-1',
     770                                'name'   => 'Test 1',
     771                        )
     772                );
     773                $child2 = self::factory()->category->create(
     774                        array(
     775                                'parent' => $parent,
     776                                'slug'   => 'test-2',
     777                                'name'   => 'Test 2',
     778                        )
     779                );
     780
     781                $terms = get_terms(
     782                        'category',
     783                        array(
     784                                'child_of'   => $parent,
     785                                'hide_empty' => false,
     786                                'fields'     => 'id=>slug',
     787                        )
     788                );
     789
     790                $this->assertEquals(
     791                        array(
     792                                $child  => 'test-1',
     793                                $child2 => 'test-2',
     794                        ),
     795                        $terms
     796                );
     797        }
     798
     799        /**
    723800         * @ticket 31118
    724801         */
Note: See TracChangeset for help on using the changeset viewer.