I'm looking to display a single featured post from my latest 3 posts at random. I've managed to get it up and running picking any post at random just fine, but I want to filter it down to only the latest 3.
<?php
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 1,
'post_status' => 'publish'
);
$rand_query = new WP_Query( $args );
if ( $rand_query->have_posts() ) :
while ( $rand_query->have_posts() ) : $rand_query->the_post();
?>
// DIV FOR SINGLE FEATURED POST HERE // etc...
Obviously, if I change the posts_per_page to 3 I then get 3 divs containing featured post previews. I only want the one post that is picked at random from those last 3. A date query won't work as the posts aren't regular.
WP_Query
, you don't want to make the DB do the random bit