I have a custom post type ‘dogs.’ I set up custom fields specifically for the dogs post type, and all of it is working great as far as getting the data in, but getting it out into the template is somewhat confusing due to some fields having serialized values.
‘Location’ is a simple custom field which allows the user to enter the location of the dog into a text box. So when I do
$location = get_post_custom_values(‘location’);
I can output that easily with
But if you look at ‘sex’, which is a radio button with values ‘male’ or ‘female’, it gets a little nutty
$sex = get_post_custom_values(‘sex’);
echo $sex; //outputs a serialized string
$sex = unserialize($sex);
echo current($sex); //outputs the value I want
Whenever the code gets silly like this, I can’t help but think there is a better way, but I’ve searched the codex and only see auto-unserialization thru functions like get_post_meta, which don’t work for the custom fields as far as I can tell.
- The topic ‘get unserialized custom post values’ is closed to new replies.