[英]Show posts only from specific CPT Taxonomy Category
我已經搜索了高低,並應用了我在 Stackoverflow 上找到的所有解決方案,但沒有運氣,所以嘗試發帖看看是否有人可以幫助我...
我試圖在我的自定義帖子類型分類法中顯示屬於某個類別的帖子。
CPT 稱為“Fabrics”,分類法稱為“Type” - 在“Type”下我有一個名為“Lycra”的類別
我想顯示“萊卡”下存在的所有帖子
這是我到目前為止的代碼,但它只列出了 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;
?>
我在這里缺少什么? 任何幫助都非常感謝
使用 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',
),
),
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.