get_post_status
apply_filters( ‘get_post_status’, string $post_status , WP_Post $post )
过滤器::过滤post状态。
Filter Hook: Filters the post status.
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$post_status | (string) | 岗位状态。 |
$post | (WP_Post) | post对象。 |
源码(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; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.4.0 | wp-includes/post.php:931 | 1 | 0 |
get_post_status 为WP2原创文章,链接:https://www.wp2.cn/hook/get_post_status-2/