wp_query类别和自定义帖子类型在一起
问题描述:
我想使类别(1,8)和自定义帖子类型(促销)的一个循环,但它不工作。 这是我的查询wp_query类别和自定义帖子类型在一起
$args = array (
'post_type' => array('promotions'),
'category__in' => array(1,8),
'posts_per_page' => -1,
);
$queryconfig = new WP_Query($args);
<?php while ($queryconfig->have_posts()) : $queryconfig->the_post(); ?>
<a href="<?php the_permalink() ?>">
<span> <?php the_title() ?></span>
</a>
<?php endwhile;?>
<?php wp_reset_postdata(); ?>
我应该怎么办?如何在一个循环中加入类别和自定义文章类型?
答
我找到了答案。 args来 表应该是这样的:
$args = array(
'post_type' => array('post', 'promotions', 'other_custom_post_type'),
'posts_per_page' => -1,
'category__not_in' => array(1,8),
);
post_type“后”包括所有类别和category__not_in排除我们不想要什么