Why is it bad to use the GUID?

I recently upgraded my WP version from 3.2.x to 3.5.x. In the process, the WP functions that retrieve images (wp_get_attachment_image_src, get_the_post_thumbnail, etc) are now broken. I had to change calls to those functions and use <img src='.$my_post->guid.'> in order to get it to work.

However, people have told me that using guid is not good. I’m not changing the value though, just using it because I can’t find any other way to get my images to load properly. The wp_get_attachment_image_src method doesn’t return anything. What’s so bad about using the guid if it doesn’t change? Is it okay in this situation?

Related posts

1 comment

  1. In a nutshell – GUID is not supposed to hold meaningful data and the fact that at this moment the data in it happens to be meaningful is coincidental.

    WordPress does no verification whatsoever that GUIDs mean anything. They are not guaranteed to stay immutable if you rely on that and they are not changed when that needs to happen if they are treated as data, for example on migration with domain changes.

    In all my history of using WP GUIDs were one of very few things that got slapped with backwards incompatible change (sanitizing strategy for them was tightened) and it exploded long deployed work project.

    You got very accurate and very practical advice – forget GUIDs exist in WordPress. Follow that advice.

Comments are closed.