How To Display Random Posts in Wordpress – WP Random Post List

Display a list of randomly selected wordpress posts using the get_posts() function by changing the value of the orderby parameter (orderby=rand):

<h2>Random Post</h2>
<ul>
  <?php $rand_posts = get_posts('numberposts=10&orderby=rand'); ?>
  <?php foreach( $rand_posts as $post ) : ?>
  <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  <?php endforeach; ?>
</ul>

Of course you can extrapolate the idea and display an image associated with the post, or other information, but I presented only the minimum possible code for the proposed objective: Random Post List.

Happy Coding!

byrev Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *