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

Allow custom queries in painless scripting language #1748

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions docs/indexables.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ ElasticPress integrates with `WP_Query` if the `ep_integrate` parameter is passe
'day' => 1,
) );
```
* ```custom_query``` (*string*)

```custom_query``` allows the user to write a custom query in the painless scripting language [https://www.elastic.co/guide/en/elasticsearch/painless/current/index.html](https://www.elastic.co/guide/en/elasticsearch/painless/current/index.html).
```php
$args['custom_query'][] = "doc['meta.birthday'].value.getMonthValue() == 3";
```

* ```date_query``` (*array*)

```date_query``` accepts an array of keys and values (array|string|int) to find posts created on
Expand Down
17 changes: 17 additions & 0 deletions includes/classes/Indexable/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,23 @@ function( $tax_query ) use ( $args ) {
$use_filters = true;
}

if ( ! empty( $args['custom_query'] ) ) {
foreach ( $args['custom_query'] as $custom_query ) {
$filter['bool']['must'][] = array(
'bool' => array(
'filter' => array(
'script' => array(
'script' => array(
'source' => $custom_query,
'lang' => 'painless',
),
),
),
),
);
}
}

/**
* Like WP_Query in search context, if no post_status is specified we default to "any". To
* be safe you should ALWAYS specify the post_status parameter UNLIKE with WP_Query.
Expand Down