WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/get post status

Contents

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

$ID
(integer) (optional) Post ID. 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.