Детские таксономии - PullRequest
0 голосов
/ 13 января 2020

У меня есть такой файл таксономии, и моя проблема в том, что дочерние объекты отображаются во всех родительских категориях (также в которых они не связаны). И как я могу скрыть родительские объекты, если они уже показаны? Может кто-нибудь помочь решить эту проблему?

<?php
$term_slug = get_query_var('term');
$taxonomy = get_query_var('taxonomy');
$term = get_term_by( 'slug', $term_slug, $taxonomy );
$term_id = $term->term_id;
$term_args = array('parent' => 0, 'orderby'=>'id', 'order'=>'ASC', 'hide_empty'=>false, );
$get_terms = get_terms($taxonomy, $term_args);
$terms = get_terms($taxonomy, array( 'child_of' => $term_id ) );
foreach($get_terms as $parent) :

?>
<?php
$parent_id = $parent->term_id; //Store the category ID as a variable to be used in WP_Query

$term_children = get_term_children( $parent_id, $taxonomy );
if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
foreach ( $term_children as $child ) {
$term = get_term_by( 'id', $child, $taxonomy );
$child_id = $term->term_id;
echo '<h3><a href="' . get_term_link( $child, $taxonomy ) . '">' . $term->name . '</a></h3>';

$args = array(
'post_type' => $post_type,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'id',
'terms' => $child_id,
),
),
);

$wpq = new WP_Query($args);
echo '<ul>';
if($wpq->have_posts()) {
while ( $wpq->have_posts() ) : $wpq->the_post();$gallery = get_field('image_gallery', get_the_ID() );
?>
    <li>
         <a href="<? the_permalink(); ?>">
            <span class="photo"><img src="<? echo $gallery[0];  ?>"/></span>
            <p class="description"><? the_title(); ?></p>

        </a>
    </li>
<?php
endwhile;
}//have_posts
echo '</ul>';
}//term_children
}
?>
<?php
endforeach;
?>
...