Last active
April 15, 2024 10:38
-
-
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/
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
/** | |
* @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