How to purge WP REST API
If you are using a cache for WordPress and want to include the WP-API, you'll have to invalidate it when a post is published or edited.
This is the list of urls you need to invalidate when a POST X is published or edited:
Important: The URL of the frontpage is
https://blog.com?rest_route=/wp/v2/posts&_embed=true&page=1&per_page=10
Other useful considerations:
- If you are using custom post types and we have activated the auto-discover feature, you need to substitute ?rest_route=/wp/v2/posts& for /wp-json/wp/v2/posts?. For example, the frontpage url would be: https://blog.com/wp-json/wp/v2/posts?_embed=true&page=1&per_page=10
- If you don't use 10 posts per page, you need to change all the per_page queries. For example, if you WP is configured like this:the frontpage url would be: https://blog.com?rest_route=/wp/v2/posts&_embed=true&page=1&per_page=7
- If you edit PAGE X, the only url you need to purge is: https://blog.com?rest_route=/wp/v2/pages/X&_embed=true
- Query params are sorted alphabetically, starting with _embed. For that reason categories go before page and per_page but tags go after it:
- When editing categories (name, slug...), tags (name, slug...) or authors (name, description...) we recommend to wipe out the entire WP-API cache as they can be included in many different queries, including custom ones.
- Media can also be included in many different queries. To avoid wiping out the entire cache, we recommend to delete the "wrong" image and upload a new one.
Last modified 4yr ago