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
4 changes: 4 additions & 0 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4464,6 +4464,10 @@ public function is_singular( $post_types = '' ) {

$post_obj = $this->get_queried_object();

if ( null === $post_obj ) {
return false;
}

return in_array( $post_obj->post_type, (array) $post_types, true );
}

Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/tests/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,20 @@ static function() {
$this->assertArrayHasKey( 'join', $posts_clauses_request );
$this->assertSame( '/* posts_join_request */', $posts_clauses_request['join'] );
}

/**
* Tests that is_singular() returns false for an undefined post object.
*
* @ticket 56188
*
* @covers ::is_singular
*/
public function test_is_singular_should_return_false_for_an_undefined_post_object() {
$query = new WP_Query;

$query->init();
$query->set( 'is_singular', true );

$this->assertFalse( $query->is_singular( 'a_post_type' ) );
}
}