2017-05-10 26 views
0

を記事を取得します。は、親分類ビューからだから、親分類ページにカスタム分類子によって

  • 子供1

    • ポスト
    • ポスト
    • ポスト
  • 子供2

    • ポスト
    • ポスト
    • ポスト
    • ポスト
  • 子供3

    • ポスト
    • ポスト
    • ポスト
    • ポスト

私はこれを解決するためにインターネットを洗い上げてきましたが、何も動作しているようだありません。私は正常にタームIDをエコーすることができますが、私はそれを何も返しませんクエリに渡すとき。

<?php 
 
    $terms = get_terms('ht_kb_category'); 
 
    if (! empty($terms) && ! is_wp_error($terms)){ 
 
     echo '<ul>'; 
 
     foreach ($terms as $term) { 
 
      if ($term->parent != 0) { 
 
       echo '<li><h1>' . $term->name . '</h1></li>'; 
 

 
       $the_query = new WP_Query(array(
 
        'post_type' => 'post', 
 
        'tax_query' => array(
 
         array (
 
          'taxonomy' => 'ht_kb_category', 
 
          'field' => 'slug', 
 
          'terms' => $term->slug, 
 
         ) 
 
        ), 
 
       )); 
 

 
       while ($the_query->have_posts()) : 
 

 
       echo '<p>'. the_title() .'</p>'; 
 

 
       endwhile; 
 

 
       /* Restore original Post Data 
 
       * NB: Because we are using new WP_Query we aren't stomping on the 
 
       * original $wp_query and it does not need to be reset. 
 
       */ 
 
       wp_reset_postdata(); 
 

 
      } 
 
     } 
 
     echo '</ul>'; 
 
    } ?>

答えて

0

は、最後にカスタム分類のURLを使用して、いくつかの探偵の仕事の後に解決策を見つけました。私は 'post_type'が不足していて、 'term_id'の代わりに'tag_id'を照会する必要がありました。

<?php $current_term_id = $hkb_current_term_id ?> 
 

 
      <?php 
 
      $myposts = get_posts(array(
 
       'showposts' => -1, 
 
       'post_type' => 'ht_kb', 
 
       'tax_query' => array(
 
        array(
 
        'taxonomy' => 'ht_kb_category', 
 
        'field' => 'tag_id', 
 
        'terms' => $current_term_id) 
 
       )) 
 
      ); 
 

 
      echo '<ul>'; 
 

 
      foreach ($myposts as $mypost) { ?> 
 
       <li><a href="<?php echo get_permalink($mypost->ID) ?>"><?php echo $mypost->post_title ?></a></li> 
 
      <?php } 
 
      echo '</ul>'; 
 
      ?>

関連する問題