Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-term-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
Expand Down
45 changes: 45 additions & 0 deletions tests/phpunit/tests/term/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading