Код:
<section>
<h2>
Возможно, вам будут полезны эти статьи:
</h2>
<div class="articles-list">
<?php global $post;
if (false === ($rand_query_results = get_transient('rand_query_results'))) {
$randargs = array('orderby' => 'rand', 'posts_per_page' => 20);
$query = new WP_Query;
$rand_query_results = $query->query($randargs);
set_transient('rand_query_results', $rand_query_results, 60 * 60 * 12);
}
$randomposts = get_transient('rand_query_results');
$randkey = array_rand($randomposts, 4);
$fourposts[0] = $randomposts[$randkey[0]];
$fourposts[1] = $randomposts[$randkey[1]];
$fourposts[2] = $randomposts[$randkey[2]];
$fourposts[3] = $randomposts[$randkey[3]];
foreach ($fourposts as $post) : setup_postdata($post); ?>
<?php get_template_part('inc/templates/content'); ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</div>
</section>