为什么这个循环重复两次?它通过属于自定义分类的某个术语来查看

时间:2015-05-13 20:32:09

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

我想遍历custom_taxonomy的特定术语,并显示属于该特定术语的帖子。我的代码目前正在重复两次,我不知道原因:

<?php
get_header();
//for a given post type, return all
?>

<?php 
$term = $wp_query->queried_object;
$storyterm =  $term->name;
?>
  <?php 

  $post_type = 'event';
  $tax =  'event-categories '; 
  $tax_terms = get_terms($tax);
  if ($tax_terms) {
    foreach ($tax_terms as $tax_term) {
      $args=array(
        'post_type' => $post_type,
        "$tax" => $tax_term->slug,
        'post_status' => 'publish',
        'event-categories' =>  $storyterm,
        'posts_per_page' => -1,
        'orderby' => 'title',
        'order' => 'ASC',
        'caller_get_posts'=> 1
      ); // END $args

      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'List of '.$post_type . ' where the taxonomy <em>'. $tax . '</em>  is <strong>'. $tax_term->name .'</strong>';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
        endwhile;
      } // END if have_posts loop
      wp_reset_query();
    } // END foreach $tax_terms
  } // END if $tax_terms

get_footer(); 

我想要实现的目标:我想循环使用custom_taxonomy的特定术语,并显示属于该特定术语的帖子

0 个答案:

没有答案