Make WordPress Core


Ignore:
Timestamp:
10/22/2025 04:28:33 PM (4 months ago)
Author:
johnjamesjacoby
Message:

Query: Prevent querying for all terms in WP_Term_Query when include is set to [0].

This change brings the include parameter of WP_Term_Query up-to-speed with the include and __in parameters of other _Query classes, so that sending a value of [0] will not unintentionally perform an unbound query that returns all Terms.

It also introduces 3 new unit tests (for the Post, Term, and User query classes) to compare this behavior between them and ensure they remain consistent going forward.

Props audrasjb, hareesh-pillai, hellofromTonya, johnjamesjacoby, mukesh27.

Fixes #47719.

File:
1 edited

Legend:

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

    r60729 r61048  
    10501050
    10511051        $this->assertContains( $t1, $q->terms );
     1052    }
     1053
     1054    /**
     1055     * @ticket 47719
     1056     */
     1057    public function test_include_should_return_no_terms_when_0() {
     1058        register_taxonomy( 'wptests_tax', 'post' );
     1059
     1060        self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     1061
     1062        $query = new WP_Term_Query(
     1063            array(
     1064                'taxonomy' => 'wptests_tax',
     1065                'include'  => array( 0 ),
     1066            )
     1067        );
     1068
     1069        $expected = array();
     1070        $this->assertSame( $expected, $query->terms );
     1071        $this->assertSame( $expected, $query->get_terms() );
    10521072    }
    10531073
Note: See TracChangeset for help on using the changeset viewer.