WordPress.org

Ready to get started?Download WordPress

Forums

Random posts not working -- followed it to the letter from Codex (4 posts)

  1. tylerdoornbos
    Member
    Posted 1 year ago #

    Hi, I'm having an issue pulling a random testimonial post in my theme -- I've tried this exactly as the codex says and no luck. Anyone see something I'm doing wrong? BTW, this is on an older install, 3.1 -- not sure if that makes a difference.

    <div id="quote-box">
         <?php $da_featured = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1', cat => '7' ) ); ?>
         <?php while ( $da_featured->have_posts() ) : $da_featured->the_post(); ?>
              <p>
    	      <?php the_content(); ?>
              </p>
    	  <em>
                   -<?php the_title(); ?>
              </em>
         <?php endwhile; ?>
    </div>
  2. esmi
    Forum Moderator
    Posted 1 year ago #

    It might help if you describe what happens when you use this code.

  3. tylerdoornbos
    Member
    Posted 1 year ago #

    Sorry, and thank you for the response.

    The code only returns the latest post in the category, rather than a single random post.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    If you have any other loops on the same page, have you tried resetting the query using wp_reset_query()?
    http://codex.wordpress.org/Function_Reference/wp_reset_query

Topic Closed

This topic has been closed to new replies.

About this Topic