0

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()) { 
the_post();
echo get_template_part( 'content');
} 
} wp_reset_query(); //doesn't work

Then here's the query_posts:

query_posts(array(
       'year' => $year,
       'monthnum' => $month
));

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

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?

1 Answer 1

2

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().

1
  • ahhhh... my bad, completely missed that. Commented Sep 17, 2013 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.