How to trigger error when not using wp_reset_postdata();? Why use it if the loop works without it?

You are missing the point of restoring the context to original state. Yes, your loops do work without reset. But anything that tries to access queried post after them will hit leftovers of your custom queries in global variables, rather than post from main query. In a literal sense the reset after your first query … Read more

Do I need to reset the loop in this code?

wp_reset_postdata() wp_reset_postdata() will restores the global $post variable to the current post in the main query. This is useful when using WP_Query to customize loops or create multiple loops on the same page. This Answer will solve all your queries about wp_reset_postdata() & WP_Query & get_posts

wp_reset_postdata() or wp_reset_query() after a custom loop?

The difference between the two is that wp_reset_query() – ensure that the main query has been reset to the original main query wp_reset_postdata() – ensures that the global $post has been restored to the current post in the main query. Indeed, looking at the source you’ll see that the wp_reset_query() calls wp_reset_postdata(). The only difference … Read more