I am getting this ouput when I export the custom field image,


I can add a function or php to covert this to URLS? but I have no idea. Can anyone help?


That is a serialized string, actually it's a serialized string of a serialized string, which is very odd. You need to convert it to an array and then get the image URLs from the IDs that it is returning.

Lets say $str is the variable that contains that string, here's how you would get the image URLs from those attachment IDs. FYI I put the second unserialize call inside an if statement so it won't break if your value ever becomes just a single serialized string

function parseUrlsFromSerializedIds($str) {
    $arr = unserialize($str);
    if (is_serialized($arr)) {
        $arr = unserialize($arr);
    $results = [];
    foreach ($arr as $imageID) {
        $url = wp_get_attachment_url($imageID);
        $results[] = $url;
    return implode(',', $results);


Inside that foreach you'll want to do something with the URL. I'm not sure what format you're trying to return them all in so I left it alone.

  • Hi thanks, but it is only returning one image instead, there can be mulipe images per car. I am creating a csv file to grab export images for a car dealership, I need the images url to output all images per car item and comma seperated. link Hopefully you can help more :) – Alex Trainor Feb 18 '19 at 19:32
  • that's the " I'm not sure what format you're trying to return them all in so I left it alone" part. I'll update the answer to get you the urls as a comma separated string – mrben522 Feb 18 '19 at 19:41
  • Your brilliant. Thankyou very much – Alex Trainor Feb 18 '19 at 21:05

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