I have this code that returns list of post title as links, but when I add the 'orderby' and 'order' parameters - it returns results but 'orderby, order, rand' do not work, can anyone tell me what I'm doing wrong? Thanks!

<ul>
   <?php $post; $cat_posts = get_posts(array('numberposts' => 10, 'orderby' => 'rand', 'order' => ASC, 'category' => $disciplineCatID));
   foreach($cat_posts as $post) : ?>
   <?php $postTitle = get_the_title(); if($title != $postTitle) :?>
   <li><a href="<?php the_permalink(); ?>">&rsaquo;&rsaquo; <?php the_title(); ?></a></li>
   <?php endif ;?>
   <?php endforeach; ?>
</ul>
link|improve this question
1  
Missing single quotes on the ASC.. just a typo or possibly related? – t31os Mar 23 '11 at 10:49
Could you be more specific on what's not working (e.g. does your code not return any results or ...)? – Manzabar Mar 23 '11 at 12:55
@t31los, tried the quotes - thanks but still no luck. @Manzabar - thank you - I've updated the information. Results are returned 'order, orderby, rand' do not take effect. Thanks you. – user3907 Mar 23 '11 at 13:43
feedback

4 Answers

Why don't you try to use query_posts instead?

Something like:

$args = array(
    'orderby' => 'rand',
    'order'    => 'ASC'
);
query_posts( $args );
link|improve this answer
1  
Thank you all for your help, silly me - it was conflicting with a plugin 'Post Type Order' (Order Post Types Objects using a Drag and Drop Sortable javascript capability) – user3907 Mar 25 '11 at 9:18
feedback

Yes, this is the correct syntax:

$args = array(
    'orderby' => 'rand',
    'order'    => 'ASC'
);
query_posts( $args );

However plugins can keep this from working properly. Try disabling ALL plugins and see if that helps. Two known plugins which keep orderby=rand from working are Post Type Order and WP_Sticky

link|improve this answer
feedback

try this code

<?php 
   remove_all_filters('posts_orderby');
   query_posts('orderby=rand'); 
?>

got the answer from here

http://www.reinaris.nl/wp/wordpress-random-post-order-not-working-orderbyrand/

link|improve this answer
feedback

You probably forgot to setup_postdata inside your foreach loop to get template tags to work.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown