^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_post_status()用法示例

get_post_status( int|WP_Post $ID = '' )

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$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 );
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

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


  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';
    	}
    ?>
    
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈