2017-12-18 3 views
0

도움이 필요하십니까 : 맞춤 분류학 WordPress의 특정 학부모 인 자녀들 만 표시해야합니다 : 내 분류 이름 : "지역", 부모 조건과 자녀 : 유럽 : - 포르투갈; - 독일; - 영국;맞춤 분류학의 특정 학부모의 자녀 조건 만 표시하고 싶습니다. WordPress

아시아 : - 중국; - 일본;

예를 들어 유럽의 아이들 만 목록에 표시해야합니다. 어떻게해야합니까? 나는 많은 방법을 시도하고 모든 부모의 모든 아이들을 표시 할 수 있습니다 :

 <?php 
     $taxonomyName = "region"; 
     //This gets top layer terms only. This is done by setting parent to 0. 
     $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false)); 
     echo '<ul>'; 
     foreach ($parent_terms as $pterm) { 
      //Get the Child terms 
      $terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false)); 
      foreach ($terms as $term) { 
       echo '<li><a href="' . get_term_link($term) . '">' . $term->name . '</a></li>'; 
      } 
     } 
     echo '</ul>'; 
    ?> 

그러나 특정 부모 만 표시해야합니다. 도움 주셔서 감사합니다.

답변

0

이미 답변을드립니다. 상위 용어를 설정하고 상위 중첩 된 foreach를 제거하십시오.

<?php 
    $taxonomyName = "region"; 
    //Could use ACF or basic custom field to get the "parent tax ID" dynamically from a page. At least that's what I would do. 
    $parent_tax_ID = '3'; 
    $parent_tax = get_term($parent_tax_ID); 
    echo '<h3>' . $parent_tax->name . '</h3>'; 
    echo '<ul>'; 
    $terms = get_terms($taxonomyName, array('parent' => $parent_tax_ID, 'orderby' => 'slug', 'hide_empty' => false)); 
    foreach ($terms as $term) { 
     echo '<li><a href="' . get_term_link($term) . '">' . $term->name . '</a></li>'; 
    } 
    echo '</ul>'; 
?> 
관련 문제