I want to query my posts and only return one post from a custom taxonomy. Is this possible?
Here is an example:
I have a custom taxonomy called Author. I have 200 posts with various authors. I want to query and display 6 posts, but I don’t want the same author ever repeated within the query. This is my query below. Thanks!
<?php $args = array('posts_per_page' => 6, 'orderby' => 'rand');
$taximg_loop = new WP_Query( $args );
while ( $taximg_loop->have_posts() ) : $taximg_loop->the_post();?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
I think that using standard
WP_Query
you should run 6 different loops, but this is overwhelming. But using a custom$wpdb
query you can do the trick…Put this function in
functions.php
after that, you can