Skip to content

Instantly share code, notes, and snippets.

@yoren
Last active February 29, 2016 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoren/8ae5076b21dc264356c6 to your computer and use it in GitHub Desktop.
Save yoren/8ae5076b21dc264356c6 to your computer and use it in GitHub Desktop.
Using meta_query With WP API V2
<?php
function my_allow_meta_query( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value', 'meta_query' ) ); // Omit meta_key, meta_value if you don't need them
return $valid_vars;
}
add_filter( 'rest_query_vars', 'my_allow_meta_query' );
<?php
$args = array(
'meta_query' => array(
array(
'key' => 'fruit',
'value' => 'banana',
),
array(
'key' => 'animal',
'value' => 'lion',
),
),
);
$query = new WP_Query( $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment