I've got a CSV file of new posts which I'll be importing straight into the database.

Is it safe to give a GUID of http://domain/?p=[n] where [n] is any number, as long as it's not a duplicate of an existing post?


Short answer: yes

The GUID field is meant to represent a globally unique identifier for the post. In WordPress we just happen to use the URL. The GUID field should never be thought of as an actual URL, though ... just an identifier for the post.

In reality, the GUID field could contain anything that's unique. But if you have two posts that share the same GUID, you might want to consider bumping one or the other. Importing the CSV of posts into an empty blog and using the WordPress Import/Export mechanism would help. Or setting [n] to be the ID the post will have after import.

  • And in reality the GUID field is never used anywhere. I had a hard time getting around this. – kaiser Apr 9 '11 at 10:52
  • It's not supposed to ... but some plugin developers fail to accept that and use it anyway. Therein lies weirdness ... – EAMann Apr 9 '11 at 14:26
  • It's not their fault. There are a lot of parts where you'll find similar unused stuff ("we might use that later" is the answer you always get) that act just fine as a trap. Explanation? Not even in core function comments... – kaiser Apr 9 '11 at 16:16

The GUID exists as a unique identifier for feeds. Feed readers need this in order to cache feeds and not keep repeating the same content.

It's not safe to give a GUID of http://domain/?p=[n] where [n] equals any number because when new content is created (including auto saves) WordPress assigns a GUID. If your GUID's don't follow the WordPress structure you will get collisions and duplicate GUID's can really mess up your feeds.

With WordPress, the GUID is http://example.com/?p= (for posts) or ?page_id= (for pages).

This SQL is an example of how to update published posts:

UPDATE `wp_posts` SET `guid`= concat('http://example.com/?p=',ID) WHERE   `post_status` = 'publish' AND `post_type` = 'post';

By using ID you are doing the same thing WordPress does. WordPress won't ever give duplicate post_id's so its safe to use.

  • Of course, if WordPress follows this structure, you can use another query parameter in the URL to get a GUID that you are sure WordPress will not generate. Something like `example.com?wpse14307_identifier=[n]'. Although it appears Opera ignores the name of the query variable. – Jan Fabry May 10 '11 at 14:20
  • GUID's aren't used for anything in WordPress. They are simply there for feeds. It's essential that the GUID is in a valid format or feed readers won't recognise them. WordPress GUID's might look like URL's but they aren't URL's. – Elpie May 11 '11 at 13:23
  • I know they are just there for feed readers. My comment would result in GUIDs that will never conflict with the ones generated by WordPress, since they use another structure - but it appears this will not work with Opera. Can you explain what is a "valid format" and what not? The discussion on the wp-hackers list now is to go to a hashed value. – Jan Fabry May 11 '11 at 14:34
  • @Jan Fabry: The format is defined in RFC4122. You can read it here: ietf.org/rfc/rfc4122.txt – Elpie May 15 '11 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.