2012-09-03 42 views
0

在其他地方看到很多帖子,但沒有什麼可以達到標準。可溼性粉劑定製分類術語描述

我需要回顯與自定義帖子類型相關的自定義分類的特定術語的描述。

現在,我做了下面的循環成功地拉了每學期海關相關內容的帖子(在這種情況下,我的自定義後的類型是「rental_gear」和我的任期是「相機」:

<? $args = array(
    'post_type'=> 'rental_gear', 
    'type' => 'cameras', 
    'order' => 'ASC' 
    );    

    $the_query = new WP_Query($args); 
    if($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); 

?> 
    <li><a href="<? the_permalink(); ?>">&rsaquo; <? the_title(); ?></a></li> 
<?php endwhile; endif; wp_reset_postdata(); ?> 

我可以在這個循環中抽出術語的描述嗎? 我試過'get_term'函數並拉動'$ term-> description;'但是這些與帖子有關,這是在概述頁面上列出來自多個帖子(因此使用循環)

回答

1

您沒有提到您的自定義分類的名稱,所以請替換your-taxonomy。T他會查詢所有rental_gear帖子camera條款your-taxonomy

<?php 
$args = array(
    'post_type' => 'rental_gear', 
    'tax_query' => array(
     array(
      'taxonomy' => 'your-taxonomy', 
      'field' => 'slug', 
      'terms' => 'camera' 
     ) 
    ) 
); 
$query = new WP_Query($args); 
+0

自定義分類是'類型'和術語'相機',工作正常! – RooWM

+0

'tax_query'功能強大;)。你可以投票答覆嗎? – developdaly

相關問題