• Resolved roylodder

    (@roylodder)


    Hi There!

    I’m working on an existing WordPress website. The site uses custom fields and one field is populated with an array.
    The custom field is called “items” and I need the value of the “description” key.

    Custom field name: items
    Array key I need the value of: description
    Array: `a:33:{
    s:4:”name”;
    s:8:”janedoe”;
    s:4:”language”;
    s:18:”English, Dutch”;
    s:12:”hobbies”;
    s:0:””;
    s:7:”work”;
    s:0:””;
    s:12:”description”;
    s:48:”Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam, soluta!”;
    }`

    Is there an easy way to do this?

    Best Roy

Viewing 2 replies - 1 through 2 (of 2 total)
  • There’s two ways ot do this depending on how that information is returned from the call to get_post_meta(). From what I’ve seen before, any arrays that are stored are normally unserialized into an array correctly and if that’s the case you can just get the value from the array.

    $value = $array ['description'];

    If the value is returned as a string that looks like you’ve got it there you’ll just need to unserlaize it yourself to get the values.

    $array = unserialize ($array);
    $value = $array ['description'];
    Thread Starter roylodder

    (@roylodder)

    Thanks! Stupid that i didn’t try that.
    Went with the following

    $array = maybe_unserialize($array);
    $value = $array ['description'];

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom field array’ is closed to new replies.