<section id="our-media">
<div class="container">
<?php
$cats = get_terms(array('post_type' => 'our-media', 'taxonomy' => 'headline'));
foreach ($cats as $cat) { ?>
<h3><?php echo $cat->name; ?></h3>
<?php };
$query = new WP_Query(array(
'post_type' => 'our-media',
'taxonomy' => 'headline',
'posts_per_page' => -1,
'order' => 'ASC', // or DESC
));
if ($query->have_posts()) { ?>
<ul>
<?php while ($query->have_posts()) {
$query->the_post(); ?>
<li>
<!-- код поста -->
</li>
<?php } ?>
</ul>
<?php }
wp_reset_postdata(); ?>
</div>
</section>
<section id="units">
<div class="container">
<?php
$cats = get_terms(array('taxonomy' => 'headline', 'post_type' => 'units'));
foreach ($cats as $cat) { ?>
<h3><?php echo $cat->name; ?></h3>
<p><?php echo $cat->description; ?></p>
<?php }
$query = new WP_Query(array(
'taxonomy' => 'headline',
'post_type' => 'units',
'posts_per_page' => -1,
'order' => 'ASC', // or DESC
));
if ($query->have_posts()) { ?>
<ul>
<?php while ($query->have_posts()) {
$query->the_post(); ?>
<li>
<!-- код поста -->
</li>
<?php } ?>
</ul>
<?php }
wp_reset_postdata(); ?>
</div>
</section>
Я так понимаю, нужно сделать проверку...
<section id="our-media">
<div class="container">
<?php
$cats = get_terms(array('taxonomy' => 'headline', 'post_type' => 'our-media'));
foreach ($cats as $cat) {
$query = new WP_Query(array(
'post_type' => 'our-media',
'tax_query' => array(
array(
'taxonomy' => 'headline',
'field' => 'term_id',
'terms' => $cat->term_id,
),
),
'posts_per_page' => -1,
'order' => 'ASC',
));
if ($query->have_posts()) { ?>
<h3><?php echo $cat->name; ?></h3>
<ul>
<?php while ($query->have_posts()) {
$query->the_post(); ?>
<li>
<!-- код поста -->
</li>
<?php } ?>
</ul>
<?php }
wp_reset_postdata();
}
?>
</div>
</section>
<section id="units">
<div class="container">
<?php
$cats = get_terms(array('taxonomy' => 'headline', 'post_type' => 'units'));
foreach ($cats as $cat) {
$query = new WP_Query(array(
'post_type' => 'units',
'tax_query' => array(
array(
'taxonomy' => 'headline',
'field' => 'term_id',
'terms' => $cat->term_id,
),
),
'posts_per_page' => -1,
'order' => 'ASC',
));
if ($query->have_posts()) { ?>
<h3><?php echo $cat->name; ?></h3>
<p><?php echo $cat->description; ?></p>
<ul>
<?php while ($query->have_posts()) {
$query->the_post(); ?>
<li>
<!-- код поста -->
</li>
<?php } ?>
</ul>
<?php }
wp_reset_postdata();
}
?>
</div>
</section>