Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

I would not do it this way, but it should not be a problem. When your template file is executed the "real main loop" already contains the posts for this page. You then execute query_posts() to do a second query, which "hides" the "real" loop, but after you are done you execute wp_reset_query() which makes the "real" loop again the active loop.

It would get confusing and lead to errors if you would embed the two loops, thus if you executed another query_posts() in that main where loop. Then you must use get_posts() or a direct WP_Queryget_posts() or a direct WP_Query to prevent errors.

Personally, I never call query_posts() myself and always use get_posts(), because it doesn't change any global variables "behind my back".

I would not do it this way, but it should not be a problem. When your template file is executed the "real main loop" already contains the posts for this page. You then execute query_posts() to do a second query, which "hides" the "real" loop, but after you are done you execute wp_reset_query() which makes the "real" loop again the active loop.

It would get confusing and lead to errors if you would embed the two loops, thus if you executed another query_posts() in that main where loop. Then you must use get_posts() or a direct WP_Query to prevent errors.

Personally, I never call query_posts() myself and always use get_posts(), because it doesn't change any global variables "behind my back".

I would not do it this way, but it should not be a problem. When your template file is executed the "real main loop" already contains the posts for this page. You then execute query_posts() to do a second query, which "hides" the "real" loop, but after you are done you execute wp_reset_query() which makes the "real" loop again the active loop.

It would get confusing and lead to errors if you would embed the two loops, thus if you executed another query_posts() in that main where loop. Then you must use get_posts() or a direct WP_Query to prevent errors.

Personally, I never call query_posts() myself and always use get_posts(), because it doesn't change any global variables "behind my back".

Source Link
Jan Fabry
  • 30.5k
  • 4
  • 90
  • 136

I would not do it this way, but it should not be a problem. When your template file is executed the "real main loop" already contains the posts for this page. You then execute query_posts() to do a second query, which "hides" the "real" loop, but after you are done you execute wp_reset_query() which makes the "real" loop again the active loop.

It would get confusing and lead to errors if you would embed the two loops, thus if you executed another query_posts() in that main where loop. Then you must use get_posts() or a direct WP_Query to prevent errors.

Personally, I never call query_posts() myself and always use get_posts(), because it doesn't change any global variables "behind my back".