Monday, 20 May 2013

Display pending post of custom type to its author only (who is only a subscriber)

Display pending post of custom type to its author only (who is only a subscriber)

Subscribers to my blog are allowed to post classifieds ('classified' being a custom post type) from the front-end. Everything works fine, and new classifieds are automatically set to "pending" until an admin sets them to "publish". When a classified is pending, it does not show up on the list, and this is fine.
Now here is the thing: when somebody tries to access the permalink of a pending classified (/classifieds/ID in my case), the classified is displayed when the user is an admin, and a 404 error is thrown otherwise. Instead, I would like the author of the pending classified to be able to see it, and other non-admin users to see a custom error saying the post was found but is not approved yet. How can I achieve this? Any suggestion would be much appreciated!

No comments:

Post a Comment