diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index a30d887aa56d1..6c634b5ca4643 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; @@ -590,9 +590,7 @@ public function get_terms() { ); } - if ( '' === $args['object_ids'] ) { - $args['object_ids'] = array(); - } else { + if ( null !== $args['object_ids'] ) { $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..6891a3f63cab8 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -451,6 +451,66 @@ 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, 'When object_ids is null, all terms should be returned without filtering.' ); + } + + /** + * @ticket 63256 + */ + 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' ) ); + + $query = new WP_Term_Query( + array( + 'taxonomy' => 'wptests_tax_1', + 'object_ids' => false, + 'hide_empty' => false, + 'fields' => 'ids', + ) + ); + + $this->assertSame( array(), $query->terms, 'When object_ids is false, no terms should be returned without filtering.' ); + } + + /** + * @ticket 63256 + */ + public function test_object_ids_zero_should_be_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', + ) + ); + + $this->assertSame( array(), $query->terms, 'When object_ids is 0, it should be treated as a numeric value and return an array.' ); + } + /** * @ticket 38295 * @group cache