我创建了一个模板,用于显示子分类法中的帖子列表。在该模板中,我使用以下代码
<?php
$term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
$a = $term->name;
$offset = isset($_POST['offset']) ? (int)$_POST['offset'] : 0; // lấy dữ liệu phái client gởi
$getposts = new WP_query(); $getposts->query('post_type=hotcheck&tax_query=array(array(taxonomy=topics&terms='.$a.'&field=slug))&post_status=publish&showposts=5&offset='.$offset);
global $wp_query; $wp_query->in_the_loop = true;
while ($getposts->have_posts()) : $getposts->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata();
die();
?>
该代码仍然有效,但不符合预期。每个人都可以看到该段
$getposts->query('post_type=hotcheck&tax_query=array(array(taxonomy=topics&terms='.$a.'&field=slug))&post_status=publish&showposts=5&offset='.$offset);
是对还是错? 请帮我 我希望以SUB(子)-分类而不是分类显示所有帖子。非常感谢
答案 0 :(得分:0)
<?php
$args = array(
'post_type' => 'your_post_type', // if you want to further filter by post_type
'tax_query' => array(
array(
'taxonomy' => 'type',
'field' => 'term_id',
'terms' => 37 // you need to know the term_id of your term "example 1"
)
)
);
$query = new WP_Query( $args );
?>
while ( query->have_posts() ):
$query->the_post();
...
endwhile