get_post_status()
get_post_status( int|WP_Post $post = null ) 根据post ID检索…
get_post_status( int|WP_Post $post = null )
根据post ID检索post状态。
Retrieve the post status based on the post ID.
目录锚点:#说明#参数#返回#源码#笔记
说明(Description)
如果post ID是附件,则将改为父post状态。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $post | (int | WP_Post) | 可选 | Post ID或Post对象。默认为全局$post。。 |
返回(Return)
(string|false)成功时发布状态,失败时发布状态。
源码(Source)
/**
* 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|WP_Post $ID Optional. Post ID or post object. Default empty.
* @return string|false Post status on success, 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 ) ) {
$parent_post_status = get_post_status( $post->post_parent );
if ( 'trash' == $parent_post_status ) {
return get_post_meta( $post->post_parent, '_wp_trash_meta_status', true );
} else {
return $parent_post_status;
}
}
}
return $post->post_status;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.0.0 | wp-includes/post.php:895 | 22 | 5 |
笔记(Notes)
一个基本的例子:
将返回其中一个:publish、future、draft、pending、private
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!