根据帖子ID检索帖子状态。

原型

get_post_status( int|WP_Post $ID = '' )

描述

如果帖子ID是附件,则将提供父帖子状态。

参数

$ID (int|WP_Post) (Optional)  帖子ID或帖子对象。

返回值

(string|false)  成功后发布状态,失败时假。

源文件

路径:wp-includes/post.php

<?php
...
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;
			}
		}
	}
	/**
	 * Filters the post status.
	 *
	 * @since 4.4.0
	 *
	 * @param string  $post_status The post status.
	 * @param WP_Post $post        The post object.
	 */
	return apply_filters( 'get_post_status', $post->post_status, $post );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_post_status/