wordpress custom post type taxonomuy lloop code example
Example: post type taxonomy loop wordpress
<?php
$categories = get_terms( 'service-category' );
foreach ( $categories as $category ):
$services = new WP_Query(
array(
'post_type' => 'services',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'service-category',
'terms' => array( $category->slug ),
'field' => 'slug'
)
)
)
);
?>
<h3><?php echo $category->name; ?></h3>
<ul>
<?php while ($services->have_posts()) : $services->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php
$services = null;
wp_reset_postdata();
endforeach;
?>