2012-12-23 23 views
0

我正在尝试制作一个定制分类标准下的所有帖子的列表。我试图列出一个定制分类标准下的所有帖子。

我创建了一个自定义帖子类型,名为“testimonial”,具有“testimonial categories”的自定义分类。在证言类别中,我创建了“同事”和“客户”这两个词。 我想创建太多的存档页面。一个将列出同事下的所有帖子,另一个列出客户下的所有帖子。 我已经创建了归档页面taxonomy-testimonial_categories-clients.php和taxonomy-testimonial_categories-colleagues.php。并且可以创建cpt褒奖下所有帖子的列表,但不能按照同事或客户的条款进行过滤。

经过对wordpress.org的研究,我相信在新的WP_Query中使用tax_query是最好的选择。 这是我正在使用的代码。

<?php   

$args = array(
'post_type' => 'testimonial', 
'tax_query' => array(
    array(
     'taxonomy' => 'testimonial_categories', 
     'field' => 'slug', 
     'terms' => 'colleagues' 
    ) 
) 
); 

$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); ?> 
<span class="frame small alignleft">     
      <?php the_post_thumbnail(thumbnail); ?> 
      <span>           
      <div class="test-content">                      
     <?php the_content(); ?>           
      </div> 
<?php endwhile; ?> 

回答

0

虽然它太晚这里仅仅是为我工作的解决方案,

$my_taxonomy_name = "your taxo. name"; 
$my_term_name = "your term name"; 
$my_term_id = -1; 

$terms = get_terms($my_taxonomy_name); 

if(count($terms)>0){ 
    foreach ($terms as $term) { 
     if($term->name == $my_term_name){ 
      $term_id=$term->term_id; 
      continue; 
     }   
    } 
$my_posts = array(); 
$postids_in_term = get_objects_in_term($term_id,'ad_setting'); 
foreach($postids_in_term as $post_id){ 
    array_push($my_posts,get_post($post_id)); 
} 

var_dump($my_posts); 
} 

在没有办法,这是优雅的,但嘿,它的工作原理!

相关问题