WordPress.org

Ready to get started?Download WordPress

Forums

Shuffle Custom Post Type Loop (2 posts)

  1. trishahdee
    Member
    Posted 1 year ago #

    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!

  2. trishahdee
    Member
    Posted 1 year ago #

    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', );

Topic Closed

This topic has been closed to new replies.

About this Topic