WordPress Custom Fields Explained For Normal People (I hope)
I was sitting here trying to write up a post on how to make e-commerce a little bit easier, and I got hung up. My favorite solution for simplifying e-commerce is to use custom fields in WordPress, and they’re really easy to use, but really hard to explain to someone who isn’t already familiar with them. Worse yet, they’re based on fundamental WordPress concepts that normal people never have to deal with. After all, we use WordPress so that a lot of the complicated programmery stuff is already done for us. So if I’m going to describe custom fields, I need to explain how pretty much all of WordPress works in the process.
The payoff will be my next post on how to use Paypal and WordPress Custom Fields to create simple, elegant and fast e-commerce pages. Stay tuned for that.
So, what is a custom field? It’s a key/value pair. What the hell does that mean?
In WordPress, there is a fundamental divide between data and display (it’s a simplistic view, but if that bugs you, you probably don’t need to read this article, then). If you’ve ever installed WordPress before, you know that it’s a two-part operation: you upload .php files to your server, and you connect those files to a mySQL database. The parts that display live on the server, and the data lives in the database.
Imagine making 100 people fill out a form. Each person fills out the same form with different information. Think of it as 1 form filled out 100 times. Now, go find a magician, and give him your stack of 100 forms. He will shake them over a box so all the words fall off into the box, hand you the box, and leave. Now you’ve really got something interesting.
Sit down with your box-full-of-words and declare “Show me the name and age of the 61st person!” Out of the box flies “Margaret V., 34″. Next, declare “Show me the name, age, and eye color of all the people named John!” The details for four different Johns appears. “Show me the last form filled out!” and the information person 100 put down appears.
Are you getting the idea? The magical box-full-of-words is your mySQL database, and your commands are the .php files on your server. When you look at a .php file on the internet, the .php files say “TITLE goes here, DATE goes over there and the CONTENT goes underneath that”, reaches into the database, pulls out, say, post #34, and populates TITLE, DATE, and CONTENT with the information saved under that post.
It might be something like:
My Day
posted 3/04/2010
Today was wonderful! I got icecream!
So, are you starting to get an idea of how the data is stored? For post #34,
- TITLE:My Day,
- DATE:03.04.2010
- CONTENT:Today was wonderful! I got icecream!
For post #35, it could be
- TITLE:I have a Cat
- DATE:03.26.2010
- CONTENT:My cat is really cute when she lays on her back
We have defined information types, and the various information filed under them. The information types are KEYS, and the various information under are the VALUES. Collectively, we make KEY/VALUE PAIRS.
WordPress comes with tons of pre-defined key/value pairs already. Why do you care? Because you can take those KEYS, and put them in the .php files in your WordPress theme and make them display VALUES.
One of the things that’s awesome about WordPress is that, if you like, you can make up your own keys on the fly, and display them in your themes. That’s what a custom field is. (We’ve finally come back around to what a custom field is, yay!) A custom field is just an arbitrary key/value pair that you make up and use for your own sinister purposes.
For example, say you want your blog posts to display your mood. In your post, you go to your custom field, create a new key called “mood”, then set it to “bouncy”. Then, in your theme, under TITLE, DATE and CONTENT, you can add MOOD, and for every post you put a “mood” custom field in, it’ll output your mood in the blog.
Cool, huh?
I’ve tried to make this really simple, but what I hope was conveyed is that custom fields can be a powerful tool. In my next post, I’ll show you how you can use custom fields to create a quick-n-dirty e-commerce application for your WordPress website.
If you have any questions at all, please hit me up in the comments. I would HATE to have gone through all that and still be unclear.
Mer made this mess on July 29th, 2010 and filed it under Tech Splatters, WordPress

Thank you, thank you for the explanation on custom fields. It was really easy to understand!