WordPress.org

Ready to get started?Download WordPress

Forums

"showposts" not working in WP_Query (3 posts)

  1. Jeffrey Cannon
    Member
    Posted 5 years ago #

    I upgraded my WordPress blog from 2.5.1 to 2.6 and noticed that this piece of code will work:

    <?php $my_query = new WP_Query('category_name=home&showposts=-1'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <?php echo ", $post->post_name"; ?>
    <?php endwhile; ?>

    And this one won't:

    <?php $my_query = new WP_Query('category_name=home&showposts=3'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <?php echo ", $post->post_name"; ?>
    <?php endwhile; ?>

    The difference between these is in the query. When I put -1 for showposts, it works. If I put any other number (ie. 3), the output disappears completely.

    What happened?

  2. Jeffrey Cannon
    Member
    Posted 5 years ago #

    Just checking to see if anyone knows what's going on?

  3. imsoper
    Member
    Posted 5 years ago #

    I had the same problem, but it looks like I had to define a category to get it to work:

    <?php query_posts('showposts=1&cat=1'); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic