Skip to content

Instantly share code, notes, and snippets.

@webpalych
Created November 11, 2016 10:27
Show Gist options
  • Select an option

  • Save webpalych/86156d1280fd5d95daf371cd4b213f2e to your computer and use it in GitHub Desktop.

Select an option

Save webpalych/86156d1280fd5d95daf371cd4b213f2e to your computer and use it in GitHub Desktop.
термины и дочерние посты
<ul>
<?php
$tax = 'services_cat';
$args = array(
'taxonomy' => $tax,
'hide_empty' => false,
);
$terms = get_terms( $args );
foreach ($terms as $term): ?>
<li class="clearfix">
<a href="<?php echo get_term_link($term->term_id , $tax)?>">
<img src="<?php the_field('service_thumb', $tax . '_' . $term->term_id)?>">
<span><?php echo $term->name; ?></span>
</a>
<?php
if (is_tax($tax,$term->term_id) || has_term($term->term_id,$tax)):
$args = array(
'post_type' => 'services',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $tax,
'terms' => $term->term_id
),
),
);
$services = new WP_Query( $args );
if ( $services->have_posts() ) : ?>
<ul>
<?php while ( $services->have_posts() ) : $services->the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_title();?></a></li>
<?php endwhile; ?>
</ul>
<?php endif;
wp_reset_postdata(); ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment