WordPress.org

Ready to get started?Download WordPress

Forums

Combine Queries - Randomise Results (2 posts)

  1. danhodkinson
    Member
    Posted 1 year ago #

    Hi all, i'm at the very end of this little puzzle, but stuck at the last bit.

    I have successfully combined my queries using the following code:

    <?php $blogposts = get_posts(array(
       				'post_type' => 'post',
       				'posts_per_page' => 10
       		 		));	?>
       		<?php $people = get_posts(array(
       				'post_type' => 'people',
       				'posts_per_page' => 2,
       				'orderby' => 'rand'
       		 		));	?>
       		<?php $mergedposts = array_merge( $blogposts, $people );?>
       		<?php global $post;?>
       		<?php foreach( $mergedposts as $post )  {
       			setup_postdata($post);

    the trouble is this displays the $blogposts, followed by the $people posts. I want it to take in all of the posts and spit them out randomly.

    I've scoured all over but can't figure this one out!

    Any help is appreciated.

    dan

  2. birgire
    Member
    Posted 1 year ago #

    hi

    you could try the shuffle() function

    http://php.net/manual/en/function.shuffle.php

Topic Closed

This topic has been closed to new replies.

About this Topic