WordPress: Run a query loop without interfering with the global $post

This example runs a query with some (prearranged) arguments to get related post thumbnails. More importantly, it’s an example of how to run a WP_Query in WordPress without affecting the global data. Notice the get_the_ID() call which checks the current scope’s post id…

Before I had the code below which was overwriting the global $post (via ->the_post()) which caused all the thumbs to be labelled as “active”.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to LinkedIn Post to StumbleUpon Post to Technorati