所以我有一個名為(“knowledge_base”)的自定義類型,它有一個名為(“section”)的分類法,其中之一是(“狗咬”)?,F在我在 example.com/section/dog-bite/ 上,我正在嘗試顯示此處的帖子。這是我到目前為止所擁有的,所以我不確定缺少什么,但它只顯示所有部分的所有帖子。$current = get_queried_object(); $args = array( 'post_type' => 'knowledge_base', 'tax_query' => array( array( 'taxonomy' => 'section', 'field' => $current->slug, 'terms' => $current->name ) ) ); // The Query $the_query = new WP_Query( $args );if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; } else { // no posts found }應該只有2個帖子
1 回答

慕姐4208626
TA貢獻1852條經驗 獲得超7個贊
檢查此代碼。
$args = array(
'post_type' => 'knowledge_base',
'tax_query' => array(
array(
'taxonomy' => 'section',
'field' => 'slug', // ‘term_id’, ‘name’, ‘slug’ or ‘term_taxonomy_id’
'terms' => $current->slug, // It's will be $term->slug
)
)
);
// The Query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消