26

Is there any way to get this

<?php 
$pc = new WP_Query ('category_name=cat1&posts_per_page=5'); 
?> 

but each time display a RANDOM different batch of 5 ones?

1
  • 1
    note that rand order is very expensive on the database
    – Tom J Nowell
    Apr 27, 2021 at 17:41

1 Answer 1

41

Please try this:

$args = array(
    'category_name'  => 'cat1',
    'posts_per_page' => 5,
    'orderby'        => 'rand',
);

$pc = new WP_Query( $args ); 

where 'rand' should give you a random order of your posts.

For more info check out the Codex on WP_Query order parameters here.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.