Within your WordPress plugin or theme, you may need to determine if a post is published, a draft, or some other status. Using the get_post_status() WordPress function will allow you to do exactly that. In this article, we will show you how to use the get_post_status() WordPress function.

If you would like more information on creating WordPress plugins, see our tutorial series on creating your first WordPress plugin.

Basic usage

<?php get_post_status( $ID ) ?>

Optional parameters

$ID: This is the only parameter that can be defined in which you can define the ID of the post that you want to get the status of. If left undefined, it will simply get the status of the current post.

Possible post statuses

The following are the possible statuses that can be returned from the get_post_status() function:

  • publish: Published posts or pages.

  • pending: Any post that is pending review or an editor or administrator.

  • draft: A post that has been saved as a draft.

  • auto-draft: This is a post that has been created but does not yet have any content.

  • future: A post that has a future publish date set.

  • private: This status is assigned to posts that are published but are only available to users who are logged in.

  • inherit: This is assigned as a revision of another post.

  • trash: The post has been placed in the trash.

Basic code example

<?php
$mypoststatus = get_post_status( 5 );
echo $mypoststatus;
?>

In this example, we are simply getting the post status of the post with ID 5 and assigning it to the $mypoststatus variable. Then using the echo command to display the contents of that variable which is the status of our post.

References

For more information on the get_post_status() function, you may take a look at the get_post_status WordPress Codex page.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!