Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to create a custom WordPress Rest Api route. https://since1979.dev/snippet-005-simple-custom-rest-api-route/
/**
* @see https://since1979.dev/snippet-005-simple-custom-rest-api-route/
*
* @uses $.ajax() https://api.jquery.com/jquery.ajax/
* @uses console.log() https://developer.mozilla.org/en-US/docs/Web/API/Console/log
*/
$(document).ready(function () {
let post = 9;
let meta = '_thumbnail_id';
$.ajax("/wp-json/mytheme/v1/meta/" + post + '/' + meta, 'get').success((data) => {
console.log(data.meta);
}).error((error) => {
console.log(error.responseJSON.message);
});
})
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.