Meta Box
Support › General › Query REST API by Meta Box Value
is there a built in way to do this? Ive googled and googled before posting... I have metabox taxonomy select fields for posts... and id like the API to show posts by metabox/taxonomy
Hi,
Did you mean querying posts by custom fields?
If so, please try this code:
add_filter( 'rest_{type}_query', function( $args ) { $args['meta_query'] = array( array( 'key' => 'my_field', 'value' => esc_sql( $_GET['field'] ), ) ); return $args; } );
REST URL:
http://site.com/wp-json/wp/v2/posts?field=test
The wildcard {type} can be: post | user | comment | attachment | custom post type | taxonomy.
{type}