Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
<?php
    $rp = new WP_Query(array(
    'post_type' => array( 'post','videos','projects' ),
    'orderby' => 'date&order=DESC',
    'posts_per_page' => 4
    ));

    while ($rp->have_posts()) : $rp->the_post();
?>

I noticed that if I change date&order=DESC to rand, it makes no difference, meaning the posts don't show up in random order even after multiple refreshes. Is there something wrong w/ this code?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

It should be this: WP_Query Order By Parameters

<?php
    $rp = new WP_Query(array(
    'post_type' => array( 'post','videos','projects' ),
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page' => 4
    ));

    while ($rp->have_posts()) : $rp->the_post();
?>
share|improve this answer
    
Thanks! Do you know why inserting rand into orderby wouldn't work? –  jwp Mar 16 '11 at 21:34
    
@jwp - The orderby parameter specifies which column's values you want to order. The order parameter specifies how those values should be ordered. (ASC, DESC, rand, ...) –  imHavoc Mar 16 '11 at 21:38
    
I did try entering the rand value into the order parameter and unfortunately it still didn't work. Also, the link in your post states that rand should go under the orderby parameter. I'm confused because neither work. –  jwp Mar 16 '11 at 21:46
    
Add surpress_filters to the query, there's no reason it shouldn't work with rand other than when some function is hooked on and changing query parameters(surpress_filters will fix that for you though). –  t31os Mar 16 '11 at 22:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.