WordPress函数:获取文章状态函数get_post_status()

追格官方小助手/ 2022年04月05日/ WordPress/ 浏览 1897

WordPress函数get_post_status(),是用来获取文章状态的,函数代码位于位于wp-includes/post.php中。


函数介绍:


<?php get_post_status($ID); ?>


函数用法:


<?php
$ post_status = get_post_status ( 888 );//假设id为888的文章类型是“publish”
echo $post_status;
 ?>


函数代码:


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;//返回文章的post_status字段
}


发表评论

暂无评论,抢个沙发...

客服 工单