woothemes/woocommerce — pull request #3021 by leewillis77 (2013-04-24 06:41:26+00:00)
Title: Avoid wp_reset_postdata, and just preserve $post

This patch came about as a customer of the product feed plugin was having problems where the images in the product feed didn't match the products. It turns out that they were embedding the [product] shortcode in their product page.

When the shortcode runs it clobbers the global $post object (By calling the_post() on its query). It plays nicely by attempting to undo this by calling wp_reset_postdata(). However that assumes that the original contents of $post came from the main query. In fact in this case they don't - so $post gets set back to the current post from the main query which is different to what it was before the shortcode was invoked.

I imagine this is a smallish edge case, but conceivably it would get triggered whenever a shortcode was invoked on a product that was being processed by a non-main loop.

This patch simply preserves the original $post ina temporary variable, and restores it instead of using wp_reset_postdata.