admin管理员组文章数量:1314349
How to get just the common posts of 2 different categories? consider this category tree:
posttype
-news
-arrangement
--course
--competetion
--other
region
-region1
-region2
-region3
Now I want to get the posts in categories 'news' and 'region2'. I have tried this:
$query = new WP_Query('category__and=12,32'); // 12=news, 32=region2
But then I get all the posts which have either category 12 or category 32. I want those posts which have both 12 and 32.
How to get just the common posts of 2 different categories? consider this category tree:
posttype
-news
-arrangement
--course
--competetion
--other
region
-region1
-region2
-region3
Now I want to get the posts in categories 'news' and 'region2'. I have tried this:
$query = new WP_Query('category__and=12,32'); // 12=news, 32=region2
But then I get all the posts which have either category 12 or category 32. I want those posts which have both 12 and 32.
Share Improve this question asked Oct 27, 2014 at 14:04 Imrul.HImrul.H 1752 silver badges14 bronze badges1 Answer
Reset to default 2category__and
needs to be an array of category ID's
category__and (array) - use category id.
You can modify your code to look like this
$query = new WP_Query( array('category__and' => array(12,32)));
本文标签: wp queryGet posts with multiple categories
版权声明:本文标题:wp query - Get posts with multiple categories 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741872444a2402273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论