Show two random posts from custom post type

You need an orderby argument.

$args = array( 
  'post_type' => 'custom_advert', 
  'posts_per_page' => 2,
  'orderby' => 'rand'
);

That should pull posts in a random order and stop after retrieving the first two, hence two random posts.

Leave a Comment