• Resolved Michael Benson

    (@michaelbenson)


    I’m trying to pull a variety of posts using the query_posts function, but for some reason they are just being ordered by most recent, instead of at random. I’m hoping someone can help me 🙂

    <?php
    $args = array(
    	'order_by' => rand,
    	'posts_per_page' => -1,
    	'post_type' => 'work'
    );
    
    query_posts($args);
    if (have_posts()) :
    while ( have_posts() ) : the_post() ?>
    
    // Content
    
    <?php
    endwhile; endif;
    wp_reset_query();
    ?>

    Using the above code I’m trying to draw all the posts I’ve created, using the new Custom Post Type functionality. The code works fine apart from that the order is not at random.

    I’ve tried deactivating all plugins to see if there was any conflict, but nothing changed.

    Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘order_by rand not working’ is closed to new replies.