我有一个名为照片库的自定义帖子类型 . 在该帖子类型中,我注册了一个名为video的分类 . 然后我在“个人”和“商业”视频下创建了两个类别 . 现在我想只显示页面部分的商业类别帖子 . 我怎样才能做到这一点?这是我尝试但无法正常工作的代码
<?php
$args = array(
'post_type'=>'photo_gallerys',
'post_status'=>'publish',
'video'=>'commercial',
'posts_per_page'=>-1,
'paged'=>get_query_var('paged')
);
// the query
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
2 回答
试试这段代码,希望你能找到解决方案
如果你想从类别slug获得帖子,那么在tax_query数组中使用这个代码
在wp查询参数中使用
'cat' => "your_cat_id
.例如,如果我想显示仅商业类别的帖子和商业广告
category id 21
,那么我将编写查询以显示帖子,如下所示: