Last active
July 21, 2020 19:41
-
-
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.
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
// 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