0

我有分类的帖子,目前可以使用 query_posts() 函数根据其类别对帖子进行OR搜索,例如,我可以通过调用 query_posts('cat=1, 2&orderby=日期&showposts=5');

但是我想做一个AND搜索,所以只获取类别 1 AND 2 的帖子。

谁能告诉我该怎么做?WordPress 文档提到传递一个category__和一个类别 ID 数组,但这似乎在 3.1 中不起作用。我是否需要使用自定义 SELECT 查询,或者 WordPress 是否有一种巧妙的方法来做到这一点?

谢谢你。

4

2 回答 2

0

请参阅文档query_posts

query_posts( array( 'category__and' => array(1,3), 'posts_per_page' => 2, 'orderby' => 'title', 'order' => 'DESC' ) );

(此组合将返回属于类别 1 和 3 的帖子,仅显示两 (2) 个帖子,按标题降序排列)

于 2011-03-29T08:48:34.787 回答
0
query_posts( array( 'category__and' => array(1,3), 'posts_per_page' => 2, 'orderby' => 'title', 'order' => 'DESC' ) );
于 2016-04-06T08:35:01.297 回答