I have the following situation: on my index.php I am showing the most recent 20 posts using WP_Query(). On the same page in another section I would like to display 3 more random posts from the archive that are not among the 20 most recent.
My code (the second WP_Query):
$archive_random_args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'offset' => 20,
'orderby' => 'rand'
);
$archive_random_query = new WP_Query($archive_random_args);
if ($archive_random_query->have_posts()) {
while($archive_random_query->have_posts()) {
$archive_random_query->the_post();
get_template_part("templates/article-random");
}
}
The problem is that, despite the offset set to 20, posts from the 20 most recent are showing in this second WP_Query loop.
Can offset
and 'orderby' => 'rand'
be used together as arguments?
PS: Currently I have 36 posts, so there are more than enough posts for the second WP_Query to pick 3 random ones not in the 20 most recent.