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.

I currently have TWO subpages under parent page ID 43. Client testimonials.. Anyway. I have the random order thing in the query $args but the order never changes. What could I be missing?

wp_reset_query();
$args=array(
  'post_parent' => 43,
  'post_type' => 'page',
  'post_status' => 'publish',
  'posts_per_page' => 2, 
  'orderby'=>'rand'
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    <h4><? echo get_post_meta($post->ID,'subtitle', true);?></h4>
    <p><? echo get_the_excerpt(); ?></p>
    <?
    endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
share|improve this question
    
Your code looks correct, and i have tested it on my theme and it worked, but when you have rand on 2 post there is a big chance that the same post is gona show after it self again. Try to refresh the page a couple of times. And a saw that you are using php shorthand, you should change that to full PHP tags: codex.wordpress.org/… –  Pontus Abrahamsson Jul 4 '12 at 21:48
    
Why did you call wp_reset_query? This implies that you used query_posts prior to this call, which would be bad. If you're using WP_Query, you want to call wp_reset_postdata instead. –  Tom J Nowell Dec 12 at 0:18

1 Answer 1

Turns out the "Custom Page Order" plugin was causing the randomization error... or rather, not allowing any randomization as it overrides it completely. Disabled the plug-in.

Whenever I need to change orders, I can enable the plugin, shuffle pages around, and then disable. But the need for this is decreasing more and more as we now have custom menu options in Wordpress.

share|improve this answer

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.