Skip to content
6 changes: 2 additions & 4 deletions src/wp-includes/class-wp-term-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'] );
}

Expand Down
60 changes: 60 additions & 0 deletions tests/phpunit/tests/term/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading