diff --git a/docs/indexables.md b/docs/indexables.md index 8382d9d477..35a5afddaa 100644 --- a/docs/indexables.md +++ b/docs/indexables.md @@ -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 diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index d23c81e11c..a9192057b4 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -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.