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.

No matter what, I CANNOT figure out why WP_Query pulls in all posts, and completely ignores posts_per_page ... I only want to show one post.

<?php

$args = array(
'post_type'      => 'post',
'orderby'        => 'date',
'order'          => 'ASC',
'posts_per_page' => -1
);

// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
?>

<div style="padding: 15px;">
    <div class="grid_4 alpha">image</div>
    <div class="grid_7 omega">
        <?php the_excerpt(); ?>
    </div>
</div>
<div style="clear: both;"></div>
<div style="height: 33px; background-color: #5ba4d8; position: relative;">
    <div style="width: 300px; line-height: 33px;"><?php the_title(); ?></div>
    <a href="" style="position: absolute; right: 0; top: 0;"><span class="nav-blog-next"></span></a>
</div>

<?php   
endwhile;

// Reset Post Data
wp_reset_postdata();
?>
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Change posts_per_page to 1 only, not -1.

Like this: 'posts_per_page' => 1

-1 means all.

share|improve this answer
add comment

From your question title, it sounds like you are trying to only pull one single post. The problem is that you have passed -1 to posts_per_page, which equates tells the query to pull in every single post.

Use:

'posts_per_page' => 1
share|improve this answer
add comment

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.