WordPress.org

Support

Support » Plugins and Hacks » Hacks » Shuffle Custom Post Type Loop

Shuffle Custom Post Type Loop

  • I am using the following code to get 10 posts from the custom post type “chirps” as part of a content fader script which works fine:

    $args = array( 'post_type' => 'chirps', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
    $data = get_post_meta( $loop->post->ID, 'chirps', true );
    static $count = 0;
    if ($count == "1") { ?>
    <div class="slide" style="display: none;"><?php the_content(); ?>
    </div>
    <?php }
    else { ?>
    <div class="slide"><?php the_content(); ?></div>
    <?php
    $count++; }
    endwhile;
    endif; ?>

    What I want is for it to display the “chirps” in random order. I’ve looked into using query_posts($query_string.'&orderby=rand'); and shuffle(query_posts( 'chirps' )); but I can’t get either one to work. Any suggestions will be greatly appreciated!

Viewing 1 replies (of 1 total)
  • Oh man… After doing more research I found the answer. I was making it more complicated then necessary…

    $args = array( 'post_type' => 'chirps', 'posts_per_page' => 10, 'orderby' => 'rand', );

Viewing 1 replies (of 1 total)
  • The topic ‘Shuffle Custom Post Type Loop’ is closed to new replies.
Skip to toolbar