Wordpress REST API get full sitemap

2k Views Asked by At

I am trying to statically generate a WordPress site, which means having a list of every url in the site e.g.

routes = [
  '/about-us',
  '/sample-page',
  '/category/uncategorized',
  '/uncategorized/hello-world'
];

I am currently loading three API endpoints I found in the documentation at: https://developer.wordpress.org/rest-api/reference/

/wp-json/wp/v2/pages
/wp-json/wp/v2/categories
/wp-json/wp/v2/posts

But this still doesn't cover all pages in the site... how can I get all pages of the site including tags etc, through the REST API? (without using plugins!)

Bonus points: If you have a recommendation how to resolve the conflict of:

/category/uncategorized
/uncategorized/hello-world

Should really be:

/uncategorized
/uncategorized/hello-world

So that static generation doesn't have missing pages!

1

There are 1 best solutions below

1
On

I think you are manually going to have to create the URLS for each category that comes back in your categories query. Surely you can get a list, and the create them each on the fly. I know it's not desirable, but what you're trying to do is not exactly cut-and-dry.

EDIT

Maybe look into WP CLI if the REST API isn't working out.