The get_post_status() WordPress function Updated on May 26, 2021 by Jeff Matson 1 Minutes, 33 Seconds to Read 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 article Create a WordPress Plugin: A Tutorial. 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. Share this Article Related Articles How to Create an Admin Account in WordPress via MySQL Create a Footer for WordPress How to Create a Gallery in WordPress without a Plugin How to Disable the WP-Cron (wp-cron.php) in WordPress How to Change Your Site URL in Your WordPress Admin Dashboard W3 Total Cache – Guide to WordPress Caching WordPress – Changing the Site URL and Home Settings How to Globally Change the Font in WordPress How to Install WordPress using Softaculous Cleaning Up Old Post Metadata in WordPress