Skip to content

Instantly share code, notes, and snippets.

@spacedmonkey
Created October 18, 2019 22:43
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 spacedmonkey/d9a3c066c63dff41470a2dedd2d8734d to your computer and use it in GitHub Desktop.
Save spacedmonkey/d9a3c066c63dff41470a2dedd2d8734d to your computer and use it in GitHub Desktop.
Get all posts for all post types in javascript.
wp.apiFetch( { path: '/wp/v2/types' } ).then( ( post_types ) => {
for ( let post_type in post_types ){
let {rest_base} = post_types[post_type];
wp.apiFetch( { path: '/wp/v2/' + rest_base } ).then( ( posts ) => {
console.log(posts);
});
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment