WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a theme homepage and would like to include an excerpt from the latest post in a specific category. In this case, the category slug is "gear". I've tried a couple options with WP_Query but am unable to get it to return only one post.

Here's my current code:

<?php $latest1 = new WP_Query();
while ($latest1->have_posts()) : $latest1->the_post(); ?>
<h1 class="home-article-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<div class="storycontent">
<?php the_excerpt(); ?>
<?php endwhile; wp_reset_query(); ?>

There are currently two posts in the "gear" category, and both are being returned. I must be misunderstanding the posts_per_page option.

If there's a better way to do this than WP_Query (making this call three times on the page, once for each category), I'm open to that as well.

share|improve this question
Did you check for the existence of a filter on 'pre_get_posts' which might override your args settings? – marfarma Aug 28 '12 at 20:07
@marfarma I'm building this theme based on _s and haven't added any filters on pre_get_posts. – ahockley Aug 28 '12 at 20:12
up vote 1 down vote accepted

Try this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query("category_name=$catName&paged=$paged&posts_per_page=1");

Basically, add the paged variable to the args -- since it's your home page, you could hard code it to equal 1, of course.

share|improve this answer
Thanks, I tweaked the code such that 'posts_per_page' => 1, 'paged' => 1 and things are now working. – ahockley Aug 29 '12 at 0:45

Your Answer


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.