InMotion Hosting Support Center

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

$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.


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

Was this article helpful?

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

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Post a Comment

Email Address:
Phone Number:

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?


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:
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!