0

I want to add a custom field to be included into my search query. That's done via meta_query, I am fully aware of that but the issue is, I don't know, where to hang into to manipulate the query args to my needs.

So I am looking for a filter, to to get into REST API search request (/wp/v2/search), any clue?

2
  • 1
    Are you saying about this endpoint /wp/v2/search ? Commented Apr 1, 2021 at 8:04
  • @gvgvgvijayan exactly Commented Apr 1, 2021 at 9:38

1 Answer 1

5

You can implement the following hook:

add_filter( 'rest_post_search_query', 'rest_search_add_custom_field_cb', 10, 2 );
function rest_search_add_custom_field_cb( $query_args, $request ) {
    // filter...

    return $query_args;
}

You can modify the search query and include additional params like meta query, etc.

The return value of this filter will be used by WordPress in the following context:

...
$query->query( $query_args );
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.