过滤自定义帖子类型中的分类

时间:2019-06-06 19:27:18

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

我正在研究基于WordPress的电影数据库。

我有2种主要的自定义帖子类型,电影和导演,并带有相对条目。在电影中,导演由自定义分类法调用,并自动链接到带有照片,个人资料等的相对自定义帖子类型页面。

在“导演”页面中,我需要调出与该导演有关的电影。

<?php
$custom_terms = get_terms('director');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'movie',
'tax_query' => array(
    array(
        'taxonomy' => 'director',
        'field' => 'slug',
        'terms' => $custom_term->slug,
    ),
),
 );
 $loop = new WP_Query($args);
 if($loop->have_posts()) {
    echo '<h2 class="terms-title">'.$custom_term->name.'</h2>';
    echo '<ul class="post-list">';
    while($loop->have_posts()) : $loop->the_post();
        echo '<li><a href="'.get_permalink().'"     title="'.get_the_title().'" target="_blank">'.get_the_title().'</a>    </li>';
endwhile;
echo "</ul>";
   }
  }
?>

我已经编写了这段代码,但实际上获得了所有导演的条款并列出了所有导演的电影。

0 个答案:

没有答案
相关问题