Skip to content

Commit

Permalink
Merge pull request #3156 from 10up/fix/check-for-admin
Browse files Browse the repository at this point in the history
Fix: Prevent exclude from search filter from being applied to admin queries
  • Loading branch information
felipeelia authored Nov 28, 2022
2 parents d46c7d5 + 593b022 commit f39c582
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/classes/Feature/Search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
30 changes: 30 additions & 0 deletions tests/php/indexables/TestPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit f39c582

Please sign in to comment.