“Inside the Loop” essentially means that function relies on data from global variables (such as $post
) that are set up when Loop runs. Note that this is not necessarily done by main Loop of query_posts()
.
In your specific code those variables are filled by $custom_posts->the_post()
calls and after that wp_reset_query()
gets those values back to initial state.