Why execute the_post()?

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?

Related posts

Leave a Reply

1 comment

  1. 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.