WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP_query issue (2 posts)

  1. Dunkkan
    Member
    Posted 5 years ago #

    Hello, I'm just starting to learn PHP and I figured out how to retrieve 9 random posts in single.php, before the main loop :

    <?php $my_query = new WP_Query('showposts=9&orderby=rand'); ?>
    	<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<?php the_title(); ?>
    	<?php the_excerpt(); ?>
    	<?php endwhile; ?>

    I'm getting beautifully several random posts, but not always the 9 posts I specified. Sometimes is giving me just 4 or 5 posts.

    Do you know how to fix that behaviour ?

    Thanks

  2. Dunkkan
    Member
    Posted 5 years ago #

    Solved with get_posts.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags