The get_post_status() WordPress function

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.

Basic usage

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.

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!