WordPress中,文章有各种状态,如下:
publish - 已发布
pending - 已审核
draft - 草稿
auto-draft - 自动草稿
future - 定时发布
private - 私有文章
inherit - 继承
trash - 垃圾箱
使用 WP_Query 查询文章时,参数 post_status 默认值为 'publish',即 WP_Query 默认只查询发布状态的文章。
代码示例:
// 单一状态
$query = new WP_Query( array( 'post_status' => 'draft' ) );
// 多个状态
$args = array(
'post_status' => array( 'pending', 'draft', 'future' )
);
$query = new WP_Query( $args );
另 post_status 支持 'any',可以查询出除了 'inherit', 'trash' 和 'auto-draft' 三种状态以外的所有文章。
$args = array(
'post_status' => 'any',
'post_type' => 'attachment'
);
$query = new WP_Query( $args );
WP_Query 的基础用法可以参考文章:WP_Query 的基础用法简介
-
WordPress函数:translate_nooped_plural 翻译并注册字符串WordPress函数:translate_nooped_plural 翻译并注册字符串
-
WordPress函数:number_format_i18n 数字国际化WordPress函数:number_format_i18n 数字国际化
-
WordPress函数:date_i18n 日期国际化WordPress函数:date_i18n 日期国际化
-
WordPress函数:esc_html_e 转义翻译的字符串并显示WordPress函数:esc_html_e 转义翻译的字符串并显示
-
WordPress函数:esc_attr_e 属性转义、翻译、显示WordPress函数:esc_attr_e 属性转义、翻译、显示
-
WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示
暂无评论,抢个沙发...