get_post_status()
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.
Uses: get_post()
1 time — 0.000357 sec (fast) | 50000 times — 0.29 sec (very fast) | PHP 7.0.5, WP 4.4.2
Hooks from the function
Return
String|false
. Post status on success, false on failure.
Usage
get_post_status( $post );
- $post(int|WP_Post)
- Post ID or post object.
Default: global $post
Examples
#1 Display the status of the post with ID 121
$status = get_post_status( 121 ); echo $status; /* Output: 'publish' - if the post is published. 'draft' - if it is a draft, etc. */
#2 Display the localized name of the post status
$status = get_post_status( 121 ); echo get_post_status_object( $status )->label; // Published
#3 Return one of:
publish
, future
, draft
, pending
, private
, trash
, auto-draft
, inherit
, custom status
.
Description for each status See here.
#4 Check post status
Code for using outside of The Loop:
if ( 'private' === get_post_status( $post_id ) ) { echo 'private'; } else { echo 'public'; }
Changelog
Since 2.0.0 | Introduced. |