亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 WordPress 的分類中獲取帖子?

如何從 WordPress 的分類中獲取帖子?

PHP
呼喚遠方 2023-10-15 17:15:51
所以我有一個名為(“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>';

}


查看完整回答
反對 回復 2023-10-15
  • 1 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號