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 appending some posts on a click event to a twentyeleven child theme. For some reason though it only works when I use the query_posts loop and not a wp_query loop. For instance here's my wp_query loop:

$args = array('year' => $year,'monthnum' => $month);
$loop = new WP_Query($args);
if($loop->have_posts()) { 
while($loop->have_posts()) { 
echo get_template_part( 'content');
} wp_reset_query(); //doesn't work

Then here's the query_posts:

       'year' => $year,
       'monthnum' => $month

// our loop
if (have_posts()) {
while (have_posts()){
get_template_part( 'content');

I've been told to avoid query posts like the plague so I'd rather use wp_query. Any thoughts on why this is happening?

share|improve this question
up vote 2 down vote accepted

Calling the_post() operates on the global $wp_query, for your custom query you need to call the method of the query object: $loop->the_post().

share|improve this answer
ahhhh... my bad, completely missed that. – UzumakiDev Sep 17 '13 at 6:37

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.