函数介绍

<?php get_post_status($ID); ?>

函数用法

<?php
$ post_status = get_post_status ( 36 );//假设id为36的文章类型是“publish”
echo $post_status;

//打印出 publish
 ?>

函数代码

get_post_status () 位于wp-includes/post.php中。

/**
 * 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.
 *
 * @since 2.0.0
 *
 * @param int $ID Post ID
 * @return string|bool Post status or false on failure.
 */
function get_post_status($ID = '') {
    $post = get_post($ID);
 
    if ( !is_object($post) )
       return false;
 
    if ( 'attachment' == $post->post_type ) {
       if ( 'private' == $post->post_status )
           return 'private';
 
       // Unattached attachments are assumed to be published
       if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) )
           return 'publish';
 
       // Inherit status from the parent
       if ( $post->post_parent && ( $post->ID != $post->post_parent ) )
           return get_post_status($post->post_parent);
    }
 
    return $post->post_status;//返回文章的post_status字段
}