說明
按ID編號檢索文章的狀態。
如果文章的ID號為附件則返回該附件文章的狀態。
用法
- <?php?get_post_status($ID);??>
參數
$ID
(整數)(可選)文章ID若未提供$ID則該函數返回False。
默認值:”
返回的值
(字符|布爾型)
返回文章的狀態,出錯時則返回False。
可能的返回值:
- ‘publish’ – 已經發表的文章或頁面
- ‘pending’ – 文章正在等待審查
- ‘draft’ – 草稿狀態
- ‘auto-draft’ – 自動保存的草稿
- ‘future’ – 未來的時間發布
- ‘private’ – 登錄后可見
- ‘inherit’ – 修訂
- ‘trash’ – 在回收站中.版本2.9.增加
示例
- <?php
- $?post_status?=?get_post_status?(?36?);
- echo?$post_status;
- ??>
修改記錄
自2.0.0版本后
源文件
get_post_status () 位于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';
- ???????
- ???????if?(?(?'inherit'?==?$post->post_status?)?&&?(?0?==?$post->post_parent)?)
- ???????????return?'publish';
- ???????
- ???????if?(?$post->post_parent?&&?(?$post->ID?!=?$post->post_parent?)?)
- ???????????return?get_post_status($post->post_parent);
- ????}
- ????return?$post->post_status;
- }