We are using in project WordPress API for displaying blog posts on frontend in our Nuxt 2 app. The problem is that we would like to create possibility of preview blog post’s draft without being logged as admin/moderator. I could not find any entries about post draft preview on https://developer.wordpress.org/rest-api/ or about letting everyone to see them. Anyone got any clues?
2
Answers
The WP REST API allows you to query posts by post type (API endpoint), and filter by post
status
.Check documentation about listing posts.
https://example.com/wp-json/wp/v2/posts?status=draft
You can use WP post statuses like
publish, future, draft, pending, private
, or custom statuses you made.Problem is that
private
anddraft
post statuses are protected: those are not public and cannot be queried without authentication. I just tried and indeed, I can query public posts, but I cannot queryprivate
anddraft
posts without my API request being authenticated.So what you could do:
Authenticate users to the API so they can query draft and private posts
Create a custom post status that is public (
public
,publicly_queryable
andexclude_from_search
parameters), so it can be queried without authentication from the API. This way you keepprivate
anddraft
statuses secured like WP wants it. And use another for "drafts that are public".You can change the "public" status of the
private
anddraft
post statuses, so they can be queried without authentication (see example). Double-check security concerns if doing so, as it would change the WP core status design.Try a publishing workflow plugin. Lots of them out there. Here’s a free one to try…
https://wordpress.org/plugins/publishpress/
I don’t know if this reroutes your other processes… but maybe you’ve already considered this method.