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.

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

1 Answer 1

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

 
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.