0
我正在嘗試製作一個定製分類標準下的所有帖子的列表。我試圖列出一個定製分類標準下的所有帖子。
我創建了一個自定義帖子類型,名爲「testimonial」,具有「testimonial categories」的自定義分類。在證言類別中,我創建了「同事」和「客戶」這兩個詞。 我想創建太多的存檔頁面。一個將列出同事下的所有帖子,另一個列出客戶下的所有帖子。 我已經創建了歸檔頁面taxonomy-testimonial_categories-clients.php和taxonomy-testimonial_categories-colleagues.php。並且可以創建cpt褒獎下所有帖子的列表,但不能按照同事或客戶的條款進行過濾。
經過對wordpress.org的研究,我相信在新的WP_Query中使用tax_query是最好的選擇。 這是我正在使用的代碼。
<?php
$args = array(
'post_type' => 'testimonial',
'tax_query' => array(
array(
'taxonomy' => 'testimonial_categories',
'field' => 'slug',
'terms' => 'colleagues'
)
)
);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post(); ?>
<span class="frame small alignleft">
<?php the_post_thumbnail(thumbnail); ?>
<span>
<div class="test-content">
<?php the_content(); ?>
</div>
<?php endwhile; ?>