【问题标题】:WP custom taxonomy description by termWP 自定义分类描述(按术语)
【发布时间】:2012-09-03 17:18:01
【问题描述】:

在其他地方看过很多帖子,但没有什么能达到目标。

我需要回应与自定义帖子类型相关的自定义分类的特定术语的描述。

现在,我正在成功执行以下循环,以便为每个术语的相关自定义帖子提取内容(在这种情况下,我的自定义帖子类型是“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;”但这些与帖子有关,这是在概述页面上列出了许多帖子的信息(因此使用了循环)

【问题讨论】:

    标签: wordpress custom-post-type custom-taxonomy taxonomy-terms


    【解决方案1】:

    您没有提及自定义分类的名称,因此请替换 your-taxonomy。这将查询在your-taxonomy 中具有camera 术语的所有rental_gear 帖子。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-21
      • 2016-08-04
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多