[英]Get custom posts and normal posts from a category
I want to display custom posts 'events' and posts under category ID=8 from normal posts. 我想在普通帖子中显示ID = 8类别下的自定义帖子“活动”和帖子。
This code isn't working as it takes all normal posts. 这段代码不起作用,因为它需要所有正常的帖子。
category => 8
is not taken into account. category => 8
不予考虑。
$type = array('events','post');
$args=array(
'post_type' => $type,
'category' => '8',
'post_status' => 'publish'
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
//do stuff
Thanks! 谢谢!
Try changing 'category' => '8'
to 'cat' => 8
. 尝试将
'category' => '8'
更改为'cat' => 8
。
The reason for this is that basically "cat" will accept category IDs, while "category" will accept category slugs. 原因是基本上“cat”将接受类别ID,而“category”将接受类别slugs。
For more information, you can refer to the following link: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters 有关更多信息,请参阅以下链接: http : //codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.