【发布时间】:2012-01-09 04:20:27
【问题描述】:
我是一名插件开发人员,我正在使用以下函数在我的插件中查询 wordpress 中的特定帖子。问题是即使$this->params['num'] 设置为 12 之类的值,查询也只返回 6 个帖子。我的插件可以找到HERE。
它对我来说很好,在大多数情况下。但是我从用户那里得到了 2 个奇怪的支持查询,在他们的情况下它不起作用。是因为旧的 wordpress 版本还是因为与他们的主题有冲突?
Here 是一个冲突页面(他使用 WP 3.0.5)
private function lcp_set_categories(){
if($this->params['name'] != '' && $this->params['id'] == '0'){
$this->cgid = $this->get_category_id_by_name($this->params['name']);
}else{
$this->cgid = $this->params['id'];
}
$lcp_category = 'cat=' . $this->cgid;
//Build the query for get_posts()
$cgquery = 'cat=' . $this->cgid .
'&posts_per_page=' . $this->params['num'] .
'&orderby=' . $this->params['orderby'] .
'&order=' . $this->params['order'] .
'&exclude=' . $this->params['excludeposts'] .
'&tag=' . $this->params['tags'] .
'&offset=' . $this->params['offset'].
'&meta_key=' . $this->params['customfield'].
'&meta_value=' . $this->params['customfieldvalue'];
$this->cgposts = get_posts($cgquery);
}
【问题讨论】:
-
更新:修改了代码,但某些主题仍然存在问题,例如 AGGREGATE 主题。我相信它与其他一些帖子循环冲突。现在我正在使用
$tmp_query = new WP_Query;根据我的理解,我认为“查询”函数调用了不使用全局 $wp_query 对象的 get_posts 函数。所以它不应该与主题循环冲突$this->cgposts = $tmp_query->query($cgquery); -
你是对的。如果您正在创建一个新的 WP_Query 对象,那么它不应与您主题中的其他查询发生冲突。尝试使用 Xdebug 调试您的插件/主题以找到您的冲突。