Created
October 2, 2015 09:09
-
-
Save tomothumb/8d9005aa77f72706d578 to your computer and use it in GitHub Desktop.
api request with filtering by custom field for Wordpress REST API v1 see: https://github.com/WP-API/WP-API/issues/1060
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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