Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
api request with filtering by custom field for Wordpress REST API v1 see: https://github.com/WP-API/WP-API/issues/1060
add_filter( 'json_query_vars', 'slug_allow_meta' );
function slug_allow_meta( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value' ) );
return $valid_vars;
}
$.ajax({
type: 'GET',
url: 'http://xxxxxxxxxx/wp-json/posts?filter[posts_per_page]=20&type[]=page&filter[orderby]=rand&filter[meta_key]=XXXXX&filter[meta_value]=YYYYY',
dataType: 'json'
}).done(function(json){
console.log(json);
}).fail(function(json){
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.