meta query - How do you get Posts by multiple meta_keys and meta_values with the Rest API V2?

I'm trying to get my Posts by multiple meta_keys and meta_values. How do I accomplish this?The URL should be lookin

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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

You 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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744624701a4584567.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信