Check if post is in draft or pending review?

Each of our posts are reviews for individual games and we occasionally have to ‘pause’ the game by changing it from published to pending review. The problem is if the page is indexed by search engines, anyone trying to visit the link will get a 404, which is obviously not desired. I’d like to instead redirect to a listing of all our games.

I can think of a few options but I’m not sure which would be preferred.

I could just do a temporary 302 redirect from that post to the game listing page. I’m not entirely sure how this will work for SEO however.

I could also do a check to see if the post is pending review (in the 404 page?), and if it is, then display the game listing page. I’m not entirely sure how to go about this. I tried finding a function to check if it’s in pending review but didn’t have any luck.

2 Answers
2

post_status is part of the $post object which you can use to determine if it is published, a draft, pending, etc.

if( $post->post_status == 'pending' )
    // do stuff

Leave a Comment