0

So i found the code below from another question on here, it displays a list of titles from a custom post type, my question is, How do i get the list to randomize?

      <?php
 $queryObject = new WP_Query( 'post_type=announcements&posts_per_page=5' );
 // The Loop!if ($queryObject->have_posts()) {
?>
<ul>
<?php
while ($queryObject->have_posts()) {
    $queryObject->the_post();
    ?>

    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
}
?>
</ul>
<?php
 }
 ?>

1 Answer 1

1

WP_Query has an orderby property which can be set to rand. If you change your query string to 'post_type=announcements&posts_per_page=5&orderby=rand' you should be good to go. You might want to take the time to read through the whole documentation for WP_Query, just so you're familiar with its capabilities.

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.