diff --git a/includes/classes/Feature/Search/Search.php b/includes/classes/Feature/Search/Search.php index a5fb672760..27cc0b2fb2 100644 --- a/includes/classes/Feature/Search/Search.php +++ b/includes/classes/Feature/Search/Search.php @@ -711,7 +711,7 @@ public function enqueue_block_editor_assets() { */ public function exclude_posts_from_search( $query ) { - if ( ! $query->is_search() || $query->is_admin() ) { + if ( is_admin() || ! $query->is_search() ) { return; } diff --git a/tests/php/indexables/TestPost.php b/tests/php/indexables/TestPost.php index 031447812f..41b8d611d4 100644 --- a/tests/php/indexables/TestPost.php +++ b/tests/php/indexables/TestPost.php @@ -7891,6 +7891,36 @@ public function testExcludeFromSearchQueryWithMetaQuery() { } + /** + * Test exclude from search filter doesn't apply for admin quries. + * + * @since 4.4.0 + */ + public function testExcludeFromSearchFilterDoesNotApplyForAdminQueries() { + + set_current_screen( 'edit.php' ); + $this->assertTrue( is_admin() ); + + $this->ep_factory->post->create_many( + 5, + array( + 'post_content' => 'test post', + 'meta_input' => array( 'ep_exclude_from_search' => true ), + ) + ); + + ElasticPress\Elasticsearch::factory()->refresh_indices(); + + $args = array( + 's' => 'test post' + ); + $query = new \WP_Query( $args ); + + $this->assertNull( $query->elasticsearch_success ); + $this->assertEquals( 5, $query->post_count ); + } + + /** * Tests get_distinct_meta_field_keys_db *