• 欢迎来到本站,本站主要做程序员相关技术、博客、笔记,如果喜欢本网站那么赶紧使用Ctrl+D 收藏吧!
  • 如果有任何疑问,可以在下方文章下方留下你的评论~

get_ post_ status() & WordPress function get the status of the current post

视频教程 9个月前 (10-01) 2次浏览 0个评论

Example 1

<?php
$ post_status = get_post_status ( 36 );//Suppose the article type with ID 36 is "publish"
echo $post_status;// publish
 ?>

Example 2

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

Description

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.

Parameters

Post ID or post object. Defaults to global $post..

Return

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

Possible return values:

  1. ‘publish’ – published articles or pages
  2. "Pending" – the article is waiting for review
  3. ‘draft ‘– draft status
  4. ‘Auto draft’ – automatically saved drafts
  5. ‘future’ – time release in the future
  6. ‘private’ – visible after login
  7. ‘inherit’ – revised
  8. ‘trash ‘– in recycle bin. Version 2.9. Added

Source

wp-includes/post.php:

/**
 * 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 $ID Post ID
 * @return string|bool Post status or 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 ) )
           return get_post_status($post->post_parent);
    }

    return $post->post_status;//Returns the post of the article_ Status field
}

中国笔友, 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:get_ post_ status() & WordPress function get the status of the current post
喜欢 (0)
发表我的评论
取消评论
表情 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址