1

i am using $post->guid to get the URL of an attached file to my post. the output is something like this: http://example.com/foo/ [where foo is the file name]. now i want to make a URL like http://example.com/wp-content/uploads/foo/ how can i code that?

1

The GUID field is not a URL and should never be used for that purpose. It's a unique identifier that happens to look like a URL, but it should never be trusted as such.

WordPress has a number of functions for retreiving attachment URLs and files:

get_children

get_attached_media

the_attachment_link

get_attachment_link

wp_get_attachment_link

wp_get_attachment_image

wp_get_attachment_image_src

wp_get_attachment_url

wp_get_attachment_thumb_file

wp_get_attachment_thumb_url

wp_get_attachment_metadata

The function wp_get_attachment_image is probably what you're looking for in this case.

|improve this answer|||||
  • tnx. i used wp_get_attachment_url () – armin Dec 22 '15 at 18:20

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.