WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I'm getting custom post types with WP_Query->query(), it isn't really necessary to execute the the_post() function, because you can iterate over the query result array. Is it considered good behaviour to do this, or is it truly just a convience method?

share|improve this question
up vote 2 down vote accepted

It is necessary to execute that function if you want to use the template functions such as the_title() & the_permalink(). You should not use it if you aren't using those kind of functions but for the themes it's generally recommended to use these functions since they automatically ensure that all wordpress filters are being applied. This functions modifies the global variables but still it's safe to use as long as you also reset the postdata after finishing the query.

Iterating the array results is useful if you're only interested in raw data.

share|improve this answer

Your Answer


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.