8

Is it necessary to reset the query after using get_posts() ?

I have been looking at this page and I don't see any reference to get_posts() ... I can't make it out for sure from this page either.

I can't see why it wouldn't be necessary ( though on my test page it doesnt cause any problems without wp_reset_postsdata() `wp_reset_query()' or ''rewind_posts()' ) but if it is which is the right function(s) to use.

22

No. get_posts() does not modify global $wp_query variable and it doesn't need to be cleaned up.

Note that if you further use setup_postdata() you do need to wp_reset_postdata() afterwards.

|improve this answer|||||
  • would this be the same for get_post()? – v3nt Nov 18 '12 at 15:32
  • @daniel Crabbe yes. get_post() also only retrieves data for you. It does not modify global variables either, unless you further explicitly do so (with setup_postdata() or whatever). – Rarst Nov 18 '12 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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