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?


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.

| improve this answer | |

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.