-
Notifications
You must be signed in to change notification settings - Fork 656
How should a user retrieve all posts that have a meta key #1599
Comments
These fields aren't filterable by default. They can be added via the add_filter( 'rest_query_vars', 'flux_allow_meta_query' );
function flux_allow_meta_query( $valid_vars )
{
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value', 'meta_compare' ) );
return $valid_vars;
} That should open up the filter for the |
Thank you! Is for v1 the same process ? I forgot to mention I was using v1 sorry! |
This works for a single meta key, but how do we use this filter to limit the results based on multiple meta keys? |
You'll need to write some custom code for this, as it isn't supported out of the box. |
@danielbachhuber Would you happen to have any resources to link to about writing a custom filter (if possible)? Like @equatorapps, I'd also like to limit results based on multiple meta keys. With v1 I was doing it like this and it seemed to work fine:
Thanks! |
How to write some custom code for two or more custom meta fields filter using with REST WP API.Can you give me the example.. example: And also how to filtering custom post type on a combination of custom taxonomies and custom meta fields? |
Leaving a note here for future spelunkers: The |
I want to retrieve all posts that have a certain meta key.
Eg: filter[meta_key] = test
filter[meta_value] = on
Passing this filter to /wp-json/posts returns all posts. What should I do in order to achieve this result ?
The text was updated successfully, but these errors were encountered: