Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post__name_in support #2194

Merged
merged 7 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 15 additions & 0 deletions includes/classes/Indexable/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,21 @@ function( $tax_query ) use ( $args ) {
$use_filters = true;
}

/**
* 'post_name__in' arg support.
*
* @since 3.6.0
*/
if ( ! empty( $args['post_name__in'] ) ) {
$filter['bool']['must'][]['bool']['must'] = array(
'terms' => array(
'post_name.raw' => array_values( (array) $args['post_name__in'] ),
),
);

$use_filters = true;
}

/**
* 'post__not_in' arg support.
*
Expand Down
29 changes: 29 additions & 0 deletions tests/php/indexables/TestPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,35 @@ public function testPostParentQuery() {
$this->assertEquals( 1, $query->found_posts );
}

/**
* Test a post_name__in query
*
* @group post
* @since 3.6.0
*/
public function testPostNameInQuery() {
Functions\create_and_sync_post(
array(
'post_content' => 'findme name in test 1',
'post_name' => 'findme-name-in',
)
);
Functions\create_and_sync_post( array( 'post_content' => 'findme name in test 2' ) );
Functions\create_and_sync_post( array( 'post_content' => 'findme name in test 3' ) );

ElasticPress\Elasticsearch::factory()->refresh_indices();

$args = array(
's' => 'findme name in',
'post_name__in' => 'findme-name-in',
Rahmon marked this conversation as resolved.
Show resolved Hide resolved
);

$query = new \WP_Query( $args );

$this->assertEquals( 1, $query->post_count );
$this->assertEquals( 1, $query->found_posts );
}

/**
* Test Tax Query NOT IN operator
*
Expand Down