0
<?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?

5

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();
?>
  • 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, ...) – Evan Yeung 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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