I’m having the same problem. It works fine for posts, but for pages the guid is always my home URL. This guy was having the same problem:
http://wordpress.org/support/topic/field-guid-is-not-being-saved-for-new-pages?replies=1
Any ideas?
Can’t see that problem myself so it must be due to placement of the code, or other code running prior to that code that’s changing the expected values of the necessary vars.
Code was tested on my local installation and i received unique guids for each result shown.
Is your code inside the loop?
I am running into this as well. It has (in my case) nothing to do with the loop as yet, as the database itself is showing the base url for the site as the GUID for all my site’s pages. Except for one trashed page and I cannot get the GUID to update/stick on any other pages whether trashed, etc. (cannot recreate condition that will store correct GUID).
Running WP 3.0.5. Will backup DB, upgrade and see if that helps at all.
P.s. here’s the query to run to see what your page GUIDs are:
SELECT ID
, post_title
, guid
FROM wp_posts
WHERE post_type = 'page'
Since upgrading to 3.1, the problem has resolved for me.
Actually you don’t even need the guid for getting a link to a post object, use get_permalink( $post_id )
instead
You should NEVER, EVER use the GUID in your site. It is a globally unique identifier for RSS readers. RSS feeds use the GUID to know which posts have been published, so they don’t republish the same content over and over. It’s not a permalink (even though it looks like one) and due to inconsistencies in behaviour over the years its not even necessarily unique, so trying to use it within WordPress itself will cause a whole lot of pain.
If you need to get an ID you need to use $post_id.
at least in my case, Elpie, I was using it within an atom feed template.
Word, thanks for the advice.