Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3637

WP API V2: Query posts by ACF

$
0
0

I would like to query my posts by filtering for a custom meta added with Advanced Custom Fields. It's a boolean meta, so every post will have something like:

GET http://localhost/wp-json/wp/v2/posts

{  ..."acf" : {"highlight" : true  }  ...}

I'm not able to filter by this meta value, even if I exposed meta_key and meta_value to the REST API in function.php:

function my_add_meta_vars ($current_vars) {    $current_vars = array_merge ($current_vars, array ('meta_key', 'meta_value'));    return $current_vars;}add_filter ('rest_query_vars', 'my_add_meta_vars');

But if I try:

GEThttp://localhost/wp-json/wp/v2/posts?filter[meta_key]=highlight&filter[meta_value]=true

I see all the posts as if the filter is ignored.


Viewing all articles
Browse latest Browse all 3637

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>