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.

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.

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

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.

share|improve this answer
    
would this be the same for get_post()? –  daniel Crabbe 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
    
good to know! thanks, Dc –  daniel Crabbe Nov 20 '12 at 11:16
add comment

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.