diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index a30d887aa56d1..953e75e062eaf 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 ( null === $args['object_ids'] || '' === $args['object_ids'] ) { $args['object_ids'] = array(); } else { $args['object_ids'] = array_map( 'intval', (array) $args['object_ids'] ); diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index f4a0a4cc5549f..190b9349b03d3 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -451,6 +451,51 @@ public function test_object_ids_cache_should_be_invalidated_by_term_relationship $this->assertSameSets( array( $terms[1] ), $found ); } + /** + * Tests that when `object_ids` is null (the default), all terms are returned without filtering. + * + * @ticket 63256 + */ + public function test_object_ids_null_returns_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, 'When object_ids is null, all terms should be returned.' ); + } + + /** + * Tests that numeric zero as `object_ids` is treated as a valid object ID, not as "not set". + * + * @ticket 63256 + */ + public function test_object_ids_zero_is_treated_as_numeric() { + register_taxonomy( 'wptests_tax_1', 'post' ); + + 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', + ) + ); + + // object_ids=0 is a valid filter (no objects have ID 0), so no terms should be returned. + $this->assertSame( array(), $query->terms, 'When object_ids is 0, it should be treated as a numeric value, not as unset.' ); + } + /** * @ticket 38295 * @group cache