How to limit posts to 1 from each term with tax_query?
-
01-11-2019 - |
Question
Need 1 post from each.
<?php
global $post; // required
$args = array (
'tax_query' => array (
'relation' => 'AND',
array (
'taxonomy' =>'category',
'field' => 'slug',
'terms' => array ('economy','the-constitution','monetary-policy','liberty')
),
array (
'taxonomy' => 'highlight',
'field' => 'slug',
'terms' => array ('lead','featured'),
'operator' => 'NOT IN'
)
)
);
$posts = get_posts($args);
foreach ($posts as $post) {
setup_postdata($post); ?>
<li class="post">
<?php if(has_post_thumbnail()): ?><div class="imgframe"><?php the_post_thumbnail('PostThumbSideBar'); ?></div><?php else: endif; ?>
<p class="meta"><?php the_category(' '); ?> <?php the_tags(' '); ?></p>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php } ?>
<?php wp_reset_query(); // reset the query ?>
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange