I'm trying to get my Posts by multiple meta_keys and meta_values. How do I accomplish this?
The URL should be looking like this:
/posts?meta_key=Example&meta_value=Example2&meta_key=Example3&meta_value=Example4
I tried to find a solution for this quite a while now, but couldn't find anything the most things where outdated. I hope someone can help me with this.
I'm trying to get my Posts by multiple meta_keys and meta_values. How do I accomplish this?
The URL should be looking like this:
/posts?meta_key=Example&meta_value=Example2&meta_key=Example3&meta_value=Example4
I tried to find a solution for this quite a while now, but couldn't find anything the most things where outdated. I hope someone can help me with this.
Share Improve this question edited Mar 27, 2020 at 20:51 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Mar 27, 2020 at 7:13 nkunku 111 bronze badge1 Answer
Reset to default 0You can hook into the rest api query and add your args from url's parameters
The code will look something like:
function query_post_by_fields($args, $request) {
$url_params = $request->get_param;
//Modify $args with your url params
return $args;
}
add_filter('rest_post_query', 'query_post_by_fields', 10, 2);
Docs:
https://developer.wordpress/reference/hooks/rest_this-post_type_query/