我需要按此顺序显示列表.. parent-sub-category-title => sub-category-title =>子类别的帖子。以下代码为我提供了父标题,但没有给我发帖。谁能告诉我为什么?
父类别标题
子类别标题
子类-交
//get all categories then display all posts in each term
$taxonomy = 'commongood-categories'; //change this name if you have taxonomy
$param_type = 'category__in';
$term_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
foreach($terms as $term){ //this foreach is for top level
if($term->parent == 0){
echo '<h2>'.$term->name.' </h2>'; //get top level category name
$term_args=array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => $term->term_id
);
$termss = get_terms($taxonomy,$term_args);
foreach( $termss as $terms ) {
$args=array(
"$param_type" => array($terms->term_id),
'post_type' => 'commongood',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = new WP_Query($args);
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<li class="series-bubble">
<div class="stext">
<span class="stitle"><a href="<?php echo get_permalink(); ?>"><?php if(get_field('optional_title')) { echo get_field('optional_title'); } else echo get_the_title(); ?></a></span>
<span class="scontent"><a href="<?php echo get_permalink(); ?>"><?php echo get_the_excerpt(); ?></a></span>
</div>
</li>
<?php endwhile;
}
}
}
}
答案 0 :(得分:1)
您必须使用tax_query
arg进行自定义分类,category__in
仅适用于类别:http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
此外,caller_get_posts
已弃用一段时间,请改用ignore_sticky_posts
。