0

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.

1
  • 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
    Commented May 18, 2013 at 20:37

1 Answer 1

0

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.