最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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/

发布评论

评论列表(0)

  1. 暂无评论