Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 :

query_posts("post_type=taxonomy_name&posts_per_page=6");
if (have_posts()) : while (have_posts()) : the_post(); 

Am i rewriting the query in query_posts()?

Edit :

if i remove the first line

query_posts("post_type=taxonomy_name&posts_per_page=6");

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

1 Answer 1

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

 
discard

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.