2015-09-06 73 views
0

我有一個自定義分類標準,稱爲「項目類型」,它是爲自定義帖子「項目」註冊的,並且我有術語「catOne」和「catTwo」。現在我想顯示所有使用catOne鏈接到catOne的自定義帖子,在我的情況下爲9.顯示內容使用從定製分類中的術語獲得帖子

因此,我成功地能夠遍歷所有帖子,但它只顯示ID但不是全部內容。

我的方法:

$cat_id = 9; 

$args = array(
    'post_type' => 'projects', 
    'tax_query' => array(
     array(
      'taxonomy' => 'project-type', 
      'field' => 'term_id', 
      'terms' => array($cat_id) 
     ), 
    ), 
); 

    $posts = get_posts($args); 

    foreach ($posts as $post) { 
    setup_postdata($post); ?> 

    <div id="post-<?php echo $post->ID; ?> <?php post_class(); ?>"> 
     <h1 class="posttitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> 

     <div id="post-content"> 
     <?php the_excerpt(); ?> 
     </div> 

    </div> 

    <?php } wp_reset_postdata(); 

輸出我得到

<div id="post-137 class=" ""=""> 
     <h1 class="posttitle"><a href=""></a></h1> 
     <div id="post-content"> 
       </div> 
    </div> 
    <div id="post-135 class=" ""=""> 
     <h1 class="posttitle"><a href=""></a></h1> 
     <div id="post-content"> 
       </div> 
    </div> 

是否有人可以幫助我在那裏,我錯了?

回答

相關問題