WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post status

Description

Retrieve the post status based on the Post ID.

If the post ID is of an attachment, then the parent post status will be given instead.

Usage

<?php get_post_status$ID ?>

Parameters

$post
(int/object) (optional) Post ID or post object. This function will will return the status of the current post if $ID is not provided.
Default: ''

Return Values

(string|boolean) 
Post status or false on failure.

Possible values are:

  • 'publish' - A published post or page
  • 'pending' - post is pending review
  • 'draft' - a post in draft status
  • 'auto-draft' - a newly created post, with no content
  • 'future' - a post to publish in the future
  • 'private' - not visible to users who are not logged in
  • 'inherit' - a revision. see get_children.
  • 'trash' - post is in trashbin. added with Version 2.9.

Examples

A basic example:

<?php
	if ( get_post_status ( $ID ) == 'private' ) {
		echo 'private';
	} else {
		echo 'public';
	}
?>

Notes

Change Log

  • Since: 2.0.0

Source File

get_post_status() is located in wp-includes/post.php.

Related

See also index of Function Reference and index of Template Tags.