Since WordPress began as a blogging platform the default set of fields that make up a post are designed to fill the needs of a blog. While WordPress has evolved into a full-featured content management system, making it work as one requires adding more fields to each post than exist by default.
WordPress has support built in for adding as many custom fields as you need to each post as post meta data. This meta data, which is stored in the post meta table can store any information you need. By creating custom post types with custom fields you can use WordPress to store, display, and search any type of data.
I wrote a series on querying for and working with WordPress meta data that has already been stored in the database. In this series, I will be focusing on getting data into custom fields.
Keep in mind that in this series when I refer to posts, I am refering to all post types generically, be they custom post types or the built-in posts or page post types.
WordPress after all is a system for adding and presenting data from a relational database system. What it can do is determined largely by what you put in your database.
Ways to Add Custom Fields to Posts
One way to create custom meta fields is the built-in custom field UI int he post editor. The built-in custom field UI is simple, and doesn't require any additional plugins, but it is very limited. The custom fields UI only handles text fields, meaning you can only save strings in these fields. It is possible to save an array as a text string, which I will show you later.
Of course, text strings and arrays are not the only type of data that you might want to store. What about image, video or other types of files? What if you need one or more additional WYSIWYG editors or the ability to upload multiple video or image files? Or what about a field that stores a point on a map via the Google Maps?
There are a handful of plugins that make it easy to add all sorts of custom fields to WordPress post types. These plugins which include Pods, Custom Fields Suite, Advanced Custom Fields, and Types allow you to add custom fields, as well as custom content types via the WordPress admin, saving you a lot of coding. Most of the time using one of these plugins is the best way to go for adding custom fields in WordPress. I will cover them later in the series.
Using a custom field plugin or the custom field UI is not required to use custom fields. You could create them, and populate the data in the fields using by writing custom code either to create forms to enter data into them or you can import your data directly to your database, or by using a CSV import plugin.
A Note On Searching
The search system that is built-in to WordPress will not search in custom fields. This is another situation where you could create your own custom search functionality, but most of the time you are better off using a plugin. If you are using a custom field plugin then it may have a search utility. If not take a look at SearchWP or Custom Field Search.
Complex Content Management Ahead
Custom fields, along with custom content types are what allows WordPress to fill whatever content management needs you throw at it. That is, if you have the right tools and plan a head.
Before beginning any content management project, you need to figure out what custom fields you need, and how you are going to create them and populate them. This series will help you understand your options for creating and populating your custom fields.
Comments