From 9720fc094acd4ad4f4d73c2cb9c23463c8e5b393 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Mon, 15 Dec 2025 21:53:56 +0530 Subject: [PATCH 1/9] Apply the patch --- src/wp-includes/class-wp-term-query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index a30d887aa56d1..3908641bee499 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -590,7 +590,7 @@ public function get_terms() { ); } - if ( '' === $args['object_ids'] ) { + if ( empty( $args['object_ids'] ) && ! is_numeric( $args['object_ids'] ) ) { $args['object_ids'] = array(); } else { $args['object_ids'] = array_map( 'intval', (array) $args['object_ids'] ); From b38ba2a43c3153d38ac294c52e819775b2f3d982 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Mon, 15 Dec 2025 21:55:51 +0530 Subject: [PATCH 2/9] Taxonomy: Add tests for handling null and zero object_ids in WP_Term_Query --- tests/phpunit/tests/term/query.php | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index f4a0a4cc5549f..1fec77afd4a8e 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -451,6 +451,48 @@ public function test_object_ids_cache_should_be_invalidated_by_term_relationship $this->assertSameSets( array( $terms[1] ), $found ); } + /** + * + * @ticket 63256 + */ + public function test_object_ids_null_should_return_all_terms() { + register_taxonomy( 'wptests_tax_1', 'post' ); + + $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax_1' ) ); + + $query = new WP_Term_Query( + array( + 'taxonomy' => 'wptests_tax_1', + 'object_ids' => null, + 'hide_empty' => false, + 'fields' => 'ids', + ) + ); + + $this->assertSameSets( $terms, $query->terms ); + } + + /** + * + * @ticket 63256 + */ + public function test_object_ids_zero_should_be_treated_as_numeric() { + register_taxonomy( 'wptests_tax_1', 'post' ); + + $term = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); + + $query = new WP_Term_Query( + array( + 'taxonomy' => 'wptests_tax_1', + 'object_ids' => 0, + 'hide_empty' => false, + 'fields' => 'ids', + ) + ); + + $this->assertIsArray( $query->terms ); + } + /** * @ticket 38295 * @group cache From afad966247fac4736c2795c9320bc3205abb7925 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Tue, 23 Dec 2025 18:24:37 +0530 Subject: [PATCH 3/9] Tests: Improve assertions in object_ids null and zero tests for clarity --- tests/phpunit/tests/term/query.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 1fec77afd4a8e..88263dd0e5fe5 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -452,7 +452,6 @@ public function test_object_ids_cache_should_be_invalidated_by_term_relationship } /** - * * @ticket 63256 */ public function test_object_ids_null_should_return_all_terms() { @@ -469,11 +468,10 @@ public function test_object_ids_null_should_return_all_terms() { ) ); - $this->assertSameSets( $terms, $query->terms ); + $this->assertSameSets( $terms, $query->terms, 'When object_ids is null, all terms should be returned without filtering.' ); } /** - * * @ticket 63256 */ public function test_object_ids_zero_should_be_treated_as_numeric() { @@ -490,7 +488,7 @@ public function test_object_ids_zero_should_be_treated_as_numeric() { ) ); - $this->assertIsArray( $query->terms ); + $this->assertIsArray( $query->terms, 'When object_ids is 0, it should be treated as a numeric value and return an array.' ); } /** From 9566ab13f063eeb514e923a4202d84856915e325 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Tue, 23 Dec 2025 18:24:46 +0530 Subject: [PATCH 4/9] Docs: Update PHPDoc for $terms property to allow null value --- src/wp-includes/class-wp-term-query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 3908641bee499..7c3494eb86393 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -76,7 +76,7 @@ class WP_Term_Query { * List of terms located by the query. * * @since 4.6.0 - * @var array + * @var array|null */ public $terms; From 766b3d5e40cd1305dee488d518b3a7b8a14f8c06 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 23 Dec 2025 21:01:42 -0800 Subject: [PATCH 5/9] Use more specific assertion --- tests/phpunit/tests/term/query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 88263dd0e5fe5..e0783b2e5d6fc 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -477,7 +477,7 @@ public function test_object_ids_null_should_return_all_terms() { public function test_object_ids_zero_should_be_treated_as_numeric() { register_taxonomy( 'wptests_tax_1', 'post' ); - $term = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); + self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); $query = new WP_Term_Query( array( @@ -488,7 +488,7 @@ public function test_object_ids_zero_should_be_treated_as_numeric() { ) ); - $this->assertIsArray( $query->terms, 'When object_ids is 0, it should be treated as a numeric value and return an array.' ); + $this->assertSame( array(), $query->terms, 'When object_ids is 0, it should be treated as a numeric value and return an array.' ); } /** From 34b3bc74170f337969d2881a571ea43272e34c31 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 23 Dec 2025 21:16:44 -0800 Subject: [PATCH 6/9] Add test case for false --- tests/phpunit/tests/term/query.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index e0783b2e5d6fc..bac8077c215a7 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -471,6 +471,26 @@ public function test_object_ids_null_should_return_all_terms() { $this->assertSameSets( $terms, $query->terms, 'When object_ids is null, all terms should be returned without filtering.' ); } + /** + * @ticket 63256 + */ + public function test_object_ids_false_should_return_all_terms() { + register_taxonomy( 'wptests_tax_1', 'post' ); + + $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax_1' ) ); + + $query = new WP_Term_Query( + array( + 'taxonomy' => 'wptests_tax_1', + 'object_ids' => false, + 'hide_empty' => false, + 'fields' => 'ids', + ) + ); + + $this->assertSameSets( $terms, $query->terms, 'When object_ids is false, all terms should be returned without filtering.' ); + } + /** * @ticket 63256 */ From 3d7f52aa8d653a38ee624059c7e0137bdc5a6ca9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 23 Dec 2025 21:33:09 -0800 Subject: [PATCH 7/9] Fix potential back-compat break for passing false as object_ids --- src/wp-includes/class-wp-term-query.php | 9 +++++---- tests/phpunit/tests/term/query.php | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 7c3494eb86393..0459c46d1b690 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -590,10 +590,11 @@ public function get_terms() { ); } - if ( empty( $args['object_ids'] ) && ! is_numeric( $args['object_ids'] ) ) { - $args['object_ids'] = array(); - } else { - $args['object_ids'] = array_map( 'intval', (array) $args['object_ids'] ); + if ( null !== $args['object_ids'] ) { + $args['object_ids'] = array_map( + 'intval', + (array) $args['object_ids'] + ); } if ( ! empty( $args['object_ids'] ) ) { diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index bac8077c215a7..1d980d41e855a 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -477,7 +477,7 @@ public function test_object_ids_null_should_return_all_terms() { public function test_object_ids_false_should_return_all_terms() { register_taxonomy( 'wptests_tax_1', 'post' ); - $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax_1' ) ); + self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax_1' ) ); $query = new WP_Term_Query( array( @@ -488,7 +488,7 @@ public function test_object_ids_false_should_return_all_terms() { ) ); - $this->assertSameSets( $terms, $query->terms, 'When object_ids is false, all terms should be returned without filtering.' ); + $this->assertSame( array(), $query->terms, 'When object_ids is false, all terms should be returned without filtering.' ); } /** From 17fa0700ec7fffa6d17608bd45d9fd50d1ffe02c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 23 Dec 2025 21:43:38 -0800 Subject: [PATCH 8/9] Fix inversion of test and message --- tests/phpunit/tests/term/query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 1d980d41e855a..6891a3f63cab8 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -474,7 +474,7 @@ public function test_object_ids_null_should_return_all_terms() { /** * @ticket 63256 */ - public function test_object_ids_false_should_return_all_terms() { + public function test_object_ids_false_should_return_no_terms() { register_taxonomy( 'wptests_tax_1', 'post' ); self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax_1' ) ); @@ -488,7 +488,7 @@ public function test_object_ids_false_should_return_all_terms() { ) ); - $this->assertSame( array(), $query->terms, 'When object_ids is false, all terms should be returned without filtering.' ); + $this->assertSame( array(), $query->terms, 'When object_ids is false, no terms should be returned without filtering.' ); } /** From d8816ee70ff6097a59eb8d8cce7133a54345bc3d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 23 Dec 2025 21:46:11 -0800 Subject: [PATCH 9/9] Go back to one-liner --- src/wp-includes/class-wp-term-query.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index 0459c46d1b690..6c634b5ca4643 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -591,10 +591,7 @@ public function get_terms() { } if ( null !== $args['object_ids'] ) { - $args['object_ids'] = array_map( - 'intval', - (array) $args['object_ids'] - ); + $args['object_ids'] = array_map( 'intval', (array) $args['object_ids'] ); } if ( ! empty( $args['object_ids'] ) ) {