2016-04-26 203 views
0

我有一个自定义帖子类型logie,它有一个自定义分类法,现在有3个选项。WordPress按自定义分类标准显示自定义帖子类型帖子

我的目标是在不同的自举行这样的显示每个分类每一个岗位:

分类标题1

发表文章张贴

分类标题2

发表文章张贴

分类标题3

后后后

所以每次Post是一个山坳的标题和文章都在一排

这是我的代码看起来像现在。标题的工作,但要获得帖子是有点棘手。我没有得到任何错误,这有点烦人...

<div class="container-full"> 
     <?php foreach ($cat as $catVal): 
       $postArg = array('post_type'=>'logie','posts_per_page'=>-1,'order'=>'desc', 
           'tax_query' => array(
                array(
                 'taxonomy' => 'logietype', 
                 'field' => 'term_id', 
                 'terms' => $catVal->term_id 
                ) 
          )); 

      $getPost = new wp_query($postArg); 
      global $post; 
     ?> 
      <div class="row"> 
       <h2><?php echo $catVal->name; ?></h2> 
       <?php if($getPost->have_posts()): ?> 
        <?php while ($getPost->have_posts()):$getPost->the_post(): ?> 
         <div class="col-md-4"> 
          <?php echo $post->post_title; ?> 
         </div> 
        <?php endwhile; ?> 
       <?php endif; ?> 
      </div> 
     <?php endforeach; ?> 
    </div> 

任何人都可以帮助我出去感谢很多!

+0

'new wp_query'应该是'new WP_Query' – Michael

回答

0

您可以使用simplier参数查询:

$postArg = array(
    'post_type'=>'logie', 
    'posts_per_page'=>-1, 
    'order'=>'desc', 
    'logietype' => $catVal->term_id 
); 

顺便说一句,我建议使用更多的本土

<?php the_title(); ?> 

它可以在需要时大呼过瘾。

相关问题