我已经搜索了很多东西,并在Stackoverflow上应用了我在这里找到的所有解决方案,但是没有运气,所以尝试发布一个帖子,看看是否有人可以帮助我...
我正在尝试显示自定义帖子类型分类法中某个类别下的帖子。
CPT被称为“结构”,而分类法则被称为“类型”-在“类型”下,我有一个名为“莱卡”的类别
我要显示“莱卡”下的所有帖子
这是我到目前为止的代码,但仅列出了Fabrics下的所有帖子:
<?php
$cat_terms = get_terms(
array(
'post_type' => 'fabrics',
'post_status' => 'publish',
'posts_per_page' => 9999999,
'orderby' => 'date',
'order' => 'DES',
'tax_query' => array(
array(
'taxonomy' => 'type',
'field' => 'slug',
'terms' => 'lycra',
),
),
)
);
if( $cat_terms ) :
echo '<ul class="fabric-listing">';
foreach( $cat_terms as $term ) :?>
<li class="each-fabric">
<a href="<?php echo get_term_link( $term );?>">
<img src="<?php the_field('imagecat', $term); ?>">
<div class="term-name">
<?php echo $term->name; ?>
</div>
</a>
</li>
<?php
wp_reset_postdata();
endforeach;
echo '</ul>';
endif;
?>
我在这里想念什么?任何帮助都非常感谢
答案 0 :(得分:0)
使用get_posts而不是get_terms
$cat_terms = get_posts(
array(
'post_type' => 'fabrics',
'post_status' => 'publish',
'numberposts' => -1,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'type',
'field' => 'slug',
'terms' => 'lycra',
),
),
)