Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active July 21, 2020 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansmith/f9f83b2b678271fc06a7e3da49631ed1 to your computer and use it in GitHub Desktop.
Save nathansmith/f9f83b2b678271fc06a7e3da49631ed1 to your computer and use it in GitHub Desktop.
Paste this into the console of any WordPress site, to see posts via Ajax.
// START: closure.
(async () => {
// Test URL.
const url = '/?rest_route=/wp/v2/posts&per_page=100';
// Example options.
const options = {
credentials: 'include',
headers: {
'content-type': 'application/json',
},
method: 'GET',
}
// Ajax.
try {
const result = await fetch(url, options);
const payload = await result.json();
// Log response.
console.log(payload);
} catch (e) {
// No-op.
}
// END: closure.
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment