这是我的wp_query:
$postagens = new WP_Query(array(
'post_type' => array('social', 'noticia', 'entretenimento', 'esporte', 'video', 'reporter', 'culinaria', 'cobertura', 'entrevista'),
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'desc'
));
当我登录时,这是$ postagens->请求:
SELECT al_posts.* FROM al_posts WHERE 1=1 AND al_posts.post_type IN ('social', 'noticia', 'entretenimento', 'esporte', 'video', 'reporter', 'culinaria', 'cobertura', 'entrevista') AND (al_posts.post_status = 'publish' OR al_posts.post_author = 1 AND al_posts.post_status = 'private') ORDER BY al_posts.post_date desc;
如果我没有登录:
SELECT al_posts.* FROM al_posts WHERE 1=1 AND ( ( al_posts.post_type = 'social' AND ( 1=1 AND ( ( al_posts.post_status IN ('publish') ) ) ) ) OR ( al_posts.post_type = 'noticia' AND ( 1=1 AND ( ( al_posts.post_status IN ('publish') ) ) ) ) OR ( al_posts.post_type = 'entretenimento' AND ( 1=1 AND ( ( al_posts.post_status IN ('publish') ) ) ) ) OR ( al_posts.post_type = 'esporte' AND ( 1=1 AND ( ( al_posts.post_status IN ('publish') ) ) ) ) OR ( al_posts.post_type = 'video' AND ( 1=1 AND ( ( al_posts.post_status IN ('publish') ) ) ) ) OR ( al_posts.post_type = 'reporter' AND ( 1=1 AND ( ( al_posts.post_status IN ('publish') ) ) ) ) ) AND al_posts.post_type IN ('social', 'noticia', 'entretenimento', 'esporte', 'video', 'reporter', 'culinaria', 'cobertura', 'entrevista') AND (al_posts.post_status IN ('publish','private')) ORDER BY al_posts.post_date desc;
是吗,我在等你的回复:D
抱歉英文不好。
答案 0 :(得分:0)
这是来自wordpress codex:
post_status(字符串/数组) - 使用帖子状态。按帖子状态检索帖子。默认值为“发布”,,但如果用户已登录,则会添加“私人”。如果查询在管理上下文(管理区域或AJAX调用)中运行,则也会添加受保护的状态。默认情况下,受保护的状态为“future”,“draft”和“pending”。
http://codex.wordpress.org/Class_Reference/WP_Query 转到状态参数。
如果你想添加.. 'post_status'=> '发布' 到您的数组只显示查询中发布的帖子