FacetWP – REST API – ajax example

mgibbs189

{{gist file=”example.js” lang=”javascript”}}
<script>
(function($) {
$(function() {
var data = {
‘facets’: {
‘make’: [‘audi’],
‘vehicle_type’: []
},
‘query_args’: {
‘post_type’: ‘cars’,
‘posts_per_page’: 4,
‘paged’: 1
},
};

$.ajax({
type: ‘POST’,
url: ‘http://wp.dev/wp-json/facetwp/v1/fetch’,
data: { data: JSON.stringify(data) },
success: function(response) {
console.log(response);
}

});
});
})(jQuery);
</script>
{{/gist}}