Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active April 15, 2024 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vanaf1979/e68c33575c2e47a478915e980c88f67b to your computer and use it in GitHub Desktop.
Save vanaf1979/e68c33575c2e47a478915e980c88f67b to your computer and use it in GitHub Desktop.
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