【说明】
按ID编号检索文章的状态。
如果文章的ID号为附件则返回该附件文章的状态。
【用法】
<?php get_post_status($ID); ?>
【参数】
$ID(整数)(可选)文章ID若未提供$ID则该函数返回False。
默认值:”
【返回的值】(字符|布尔型)
返回文章的状态,出错时则返回False。
可能的返回值:
'publish' – 已经发表的文章或页面
'pending' – 文章正在等待审查
'draft'– 草稿状态
'auto-draft' – 自动保存的草稿
'future' – 未来的时间发布
'private'– 登录后可见
'inherit' – 修订
'trash'– 在回收站中.版本2.9.增加
【示例】
<?php
$post_status = get_post_status ( 36 );//假设id为36的文章类型是“publish”
echo $post_status;
//打印出 publish
?>
【修改记录】自2.0.0版本后
【源文件】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字段
}