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

im creating a wordpress query for custom taxonomy. However im unable to get the last post that i queried to go to the permalink. Please could somebody help me get this query right, much appreciated in advance.

Template Name: taxonomy-slug

<?php get_header(); ?>  

<?php $loop = new WP_Query( array( 'post_type' => 'business', 'town' => 'cpt-cuisine', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
     <ul data-role="listview" data-theme="c" data-inset="false">               
     <a href="<?php the_permalink(); ?>">
     <img style="margin-left: 0px; height: 65px;" alt="sample" src="<?php the_field('business_logo'); ?>" align="left"/>
     <h2><?php the_title(); ?></h2>
     <p><?php the_field('business_slogan'); ?></p></a>
<?php endwhile; ?>

<?php wp_reset_query(); ?>

<?php get_footer(); ?>

kind regards

share|improve this question

You don't need to call wp_reset_query() here, because you're not modifying the main query. Instead, call wp_reset_postdata().

You only need to call wp_reset_query() when modifying the main loop via query_posts() (which you shouldn't do, anyway, so you should never need to call wp_reset_query()).

But new WP_Query(), with a properly instantiated loop - i.e. one that calls the_post() - will stomp on the $post data for the main query. So, after closing your custom WP_Query() loop, call wp_reset_postdata() to restore $post data to the main query.

share|improve this answer

Try changing

<?php wp_reset_query(); ?>


<?php wp_reset_postdata(); ?>

As codex says "After looping through a separate query, this function restores the $post global to the current post in the main query"

Instead wp_reset_query destroys the previous query used on a custom Loop.

share|improve this answer
This was automatically flagged as "low-quality because of its length and content", which I am sure you don't want. Try to add more detail and explanation to avoid that. – s_ha_dum Feb 21 '13 at 20:49

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.