1

I realise comparing this particular website with all the other WP sites I've built that all the others have the image url in the guid column of the wp_posts table, yet this problem site just has "guid" as the value of the guid column for ALL it's image/attachment entries.

The site still seems to work fine... if I go to the "Media" area of the admin it lists all the uploaded images correctly. I assume the code is looking at the "_wp_attachment_metadata" fields in wp_postmeta to obtain their urls.

Ideally I want to

  1. know how this happened - ie is this by design in some scenarios? was there a bug in WP at some point causing this?
  2. Correct the issue replacing these values with the image urls as I have a function that tries to determine the image id of an image from it's url and that fails on this site (based on this code).
  • Re: point 2. The guid is not intended to be an accurate representation of the URL to the attachment. It's merely using the URL as a unique identifier. To get the ID of an attachment based on the URL use attachment_url_to_postid(). – Jacob Peattie Aug 2 '18 at 16:17
  • Amazing thanks @JacobPeattie write it up as an answer if you want some points! – AdamJones Aug 2 '18 at 17:23

Your Answer

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

Browse other questions tagged or ask your own question.