返回介绍

get_post_status()

发布于 2017-09-10 23:56:02 字数 4053 浏览 1061 评论 0 收藏 0

get_post_status( int|WP_Post $ID = '' )

Retrieve the post status based on the Post ID.


description

If the post ID is of an attachment, then the parent post status will be given instead.


参数

$ID

(int|WP_Post) (Optional) Post ID or post object.

Default value: ''


返回值

(string|false) Post status on success, false on failure.


源代码

File: wp-includes/post.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 );
}

更新日志

Versiondescription
2.0.0Introduced.

相关函数

Uses

  • wp-includes/post.php: get_post_status
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_post_meta()
  • wp-includes/post.php: get_post()
  • wp-includes/post.php: get_post_status()

Used By

  • wp-includes/theme.php: _wp_keep_alive_customize_changeset_dependent_auto_drafts()
  • wp-includes/nav-menu.php: _wp_delete_customize_changeset_dependent_auto_drafts()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post()
  • wp-includes/embed.php: get_oembed_response_data()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_pane_settings()
  • wp-includes/comment.php: wp_handle_comment_submission()
  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::save_post()
  • wp-admin/includes/post.php: redirect_post()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save()
  • wp-includes/class-wp-query.php: WP_Query::get_posts()
  • wp-includes/link-template.php: get_post_permalink()
  • wp-includes/post.php: wp_set_post_categories()
  • wp-includes/post.php: wp_delete_post()
  • wp-includes/post.php: get_post_status()
  • wp-includes/canonical.php: redirect_canonical()
  • wp-includes/nav-menu.php: wp_setup_nav_menu_item()
  • Show 11 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    A basic example:

    
    <?php
    	if ( get_post_status ( $ID ) == 'private' ) {
    		echo 'private';
    	} else {
    		echo 'public';
    	}
    ?>
    
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文