“So when you make up a custom post type and you assign custom fields to it, it can be a good idea to associate a custom taxonomy with it as well.”
Oh! The pain of speaking WordPress!
If that sentence didn’t twist your brain, even just a little, then this post probably isn’t for you. (You’ve obviously already had your brain twisted.)
But if you’re like most of us, then these three terms—custom fields, custom posts types, and custom taxonomies—probably don’t just roll off your tongue at the drop of a plugin.
HOWEVER … understanding each of these terms might end up helping you improve your site immensely. When you understand them and how they can work together, then you can begin to appreciate their power. And if you can appreciate their power, then you’re much more likely to try to harness that power.
Featured Plugin - WordPress Membership Site Plugin
Part 1 of a Series
This post is the first in a series.
The first thing to know about this series is that it will not go into a lot of the technical details for each function. Rather, it is meant to serve as an overview in order to help you understand the purpose of each on your site. We’ll look at how these three things are different, but also how they work together – and they DO work together.
Today we’ll go over Custom Fields.
To get a basic understanding, you can think of a “field” as just like any field in a form that you might fill out (either on the web or on paper).
In fact, you are already familiar with WordPress “fields” even if you didn’t know it. You use them all the time.
- You use the Title Field to put your titles in.
- You use the Editor Field to write your posts in.
- You use the Category Field to put your posts in categories.
- You use the Tags Field to put your tags in.
And so a “custom field” is just like any of those other fields, except it’s “custom,” of course. You (or a plugin developer or theme developer) can make one up from scratch.
Built-In Custom Post Fields
There is a custom fields mechanism built into the WordPress editor. In all honesty, unless you have a pretty good idea about what you’re doing, then using this option (as opposed to a plugin) is a little messy and a little clunky. But we’ll go over it because the basic idea behind it is not that difficult to understand, and if you can understand it, then it will help you understand the power and possibilities of custom fields better (as well as any custom fields plugin you might use).
On Your Write / Edit Page
If you don’t see the custom fields section below your editor, then you probably need to check the appropriate box on your Screen Options panel.
Featured Plugin - WordPress Infinite SEO Plugin
Compare It to Your Post Title
As you can see in the screenshot above, the custom fields mechanism has two sections — the “Name” section (the field name) and the “Value” section.
As mentioned before, think of the box for your title at the top of any regular post. You might think of the “field name” for that as being “Title,” and the value is whatever you title your post (for example: “My Summer Vacation”).
Your theme already has the code inserted for the title box. Basically it says, “Get the ‘Title’ and put it here.” So when you enter “My Summer Vacation” in the box and hit publish, the words “My Summer Vacation” get printed where the code is.
The difference with “custom fields” is that because these are “custom,” you are making up both the field name and the value of it yourself. And, of course, you will also need to insert the code into your theme yourself.
A Very Basic Example
As a VERY basic illustration, let’s say I want to print some extra text at the bottom of my post that’s not part of my post. Let’s say I would like to use this bit of text on a lot of posts but not all the posts; therefore, I make a custom field for it, so I can add it when I like.
I make a new field, and I title it “My Text.” Then I fill in the value with my text, in this case, “This is my test text. Let’s see if it shows up when I put the code in.”
I then insert my code for the custom fields into my theme at the bottom of my post.
<?php the_meta(); ?>
(Note: As mentioned, this is a VERY basic example. You can both control the output in a more complex way as well as include lots of other things besides text. However, the code you will need to achieve more sophistication may also need to be more sophisticated.)
Featured Plugin - WordPress Wiki Plugin
More Permanent Custom Fields
You can also put more permanent custom fields on your editing screen if you like. By that I mean you can permanently include a box on your screen that looks like your categories box, or your tags box, or your title box, or even your main WYSIWYG editor box. You can use drop-down menus, radio buttons, and more.
For example, you might get a plugin that lets you assign a rating for something (restaurants, movies, etc.) from 1-5 stars. Over on the side of your screen under you Tags box, you now have a drop-down menu that lets you choose how many stars you’d like to give what you’re reviewing.
Let’s say you choose three stars. The plugin (or you) inserts code into your theme that basically says, “Get the value inserted for the ‘Rating’ field.” In your case you chose three, and so the plugin goes and fetches an image of three stars and displays it wherever the code was placed (maybe at the top of your post, for example).
Make Your Own Permanent Boxes
While a plugin that you activate may add a permanent custom fields box to your write/edit screen, you can also get plugins that let you create your own boxes. There are a number of these plugins out there (search “custom fields plugin”), and because of the control and power they offer you, many are very popular. As an example, the other day I went over a custom fields plugin called More Fields.
In that example, I set up a box for restaurant reviews. Here’s a screen shot of a drop down menu I created with that plugin that was meant to give an opinion of the restaurant’s food.
Custom Boxes Only When You Want Them
Permanent custom fields are nice, but the problem is you might not want them all the time. For example, it would be nice to have them when you write a restaurant review as in the example above, but if you only write restaurant reviews 20% of the time, they just take up space. And you might want that space for other “permanent” custom fields boxes.
The solution to this problem is to create “custom post types.” And so that’s what we’ll go over in Part 2 of this series.
In the meantime, you might want to play around with some custom fields to really get the hang of the idea. You might even want to download a plugin and do it that way. You can follow the post mentioned above for the More Fields plugin.
(If you’d like to check out more technical information on custom fields, you do so in the WordPress Codex.)
Featured Plugin - WordPress Q&A Site Plugin
Photo: Recycling Symbol 3D from BigStock