DiggingIntoWordPress

by Chris Coyier & Jeff Starr

Splitting Up Custom Field Values

I’ve worked on sites in the past where I needed to get two values out of a custom field. For example, I was creating an eCommerce site where some products had options. The options were in a dropdown menu. Each option in the dropdown had a value for what you actually see, and then another value for how that option effected the price. When entering a custom field, I often did it like this:

Then in the template file, I pulled in the custom fields and split them apart using PHP’s explode() function based on the “|” character. Works fine really, but the pipe character is rather clunky to use in that way. Jermaine Oppong over at Graphicbeacon shows how he has done it by using linebreaks in the value instead, then using PHP’s nl2br and exploding based on “<br />“.

Update (2013/03/03): This post refers to a site or page that has been taken offline. If you happen to know where it’s been moved, drop us a line and we’ll restore the post with a link. Original resource (now 404): http://www.graphicbeacon.com/how-to-split-and-categorize-wordpress-custom-field-values/

Comments are closed. Contact us with any critical information. Thank you!

Code is poetry