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 am using taxonomy.php to fetch some rows from database. On taxonomy page the function get_queried_object() shows that I have got the right results from database but wordpress loop if ( have_posts() ) : while ( have_posts() ) : the_post(); is looping over all rows from database. Does have_posts() always iterates over all rows in database?

Edit :

if (have_posts()) : while (have_posts()) : the_post(); 

Am i rewriting the query in query_posts()?

Edit :

if i remove the first line


the loop is not printing any thing.

share|improve this question
the loop displays whatever is in the global query object. the query for a taxonomy term happens before the template is loaded, i'll guess that you're creating a new query in the template with incorrect parameters and overwriting the default. edit your question to show us the contents of your taxonomy.php file. – Milo May 18 '13 at 20:37

have_posts() iterates over all posts found and actually returned in the query which depend in the posts_per_page parameter.

And for your second question, using query_posts() does overwrite the query and its not really the recommend method to alter or modify the query result, here is a nice question that explains better ways : When should you use WP_Query vs query_posts() vs get_posts()?

share|improve this answer

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.