Every WordPress developer does (or should) know about Custom Post Types since the release of Thelonious (version 3.0). If not then take 5 to go read up on them. In a new WordPress site I am developing, I thought I would use the new Custom Post Type feature together with custom taxonomies. In my scenario I wanted to add “Products” to the site. I also wanted to categorize the products and assign a “Brand” (or manufacturer) to each product. I then wanted to take it a step further, and have custom fields for a product e.g. Price, Image, Delivery Times etc. There are many blogs and tuts on adding custom post types to your blog, but I was feeling lazy. I wanted to add a custom post type without looking at code, so I tried a couple plugins:
- Easy Post Types - website - info & download
- WP Post Type UI - website - info & download
- Custom Post Type UI - info & download
After trying them all I ended up going with the Custom Post Type UI plugin. Don’t get me wrong, there is nothing wrong with the others, and I actually preferred the interface used in WP Post Type UI, but I was wanting to use another plugin to enhance the custom post types and Custom Post Type UI plugin was the only one that worked with it. The other plugin in question is :
- Verve Meta Boxes - website - download
From the site : “Verve Meta Boxes is a robust custom fields plugin with an intuitive, polished interface that allows for creation of text, textarea, image, file, date, select, radio, and checkbox custom fields for posts and/or pages.”
Sweet, so it adds extra stuff to posts or pages. But it also works with custom post types!!! Yeeehaaa! These are steps I followed to create my better custom post types:
Step By Step
Download, install and activate both plugins : Custom Post Type UI (currently ver. 0.6.1) and Verve Meta Boxes (currently ver. 1.2.5). Please see the Problems section below before you continue. You should see these new admin menu options:
Click Add New under the Custom Post Types menu and enter in the values for a simple Products custom post type and save it:
Then add a new Custom Taxonomy
and save it (make sure to Select TRUE for Hierarchical) :
You will notice some new admin menu options:
Under tools, click
Verve Meta Boxes
, then create a new meta box:
Then add any fields you might want to capture for your products:
Then add products, and you will notice a nice new box where you can specify the product info:
AWESOME!!!! You can then access the product info the same way you would normally access custom fields, using get_post_meta or get_post_custom_values.
I did encounter some bugs in Verve Meta Boxes plugin and this is how to fix them:
- The table created to store the Meta Box fields (usually “wp_verve_meta_fields” but depends on your table prefix) has a column named “verve_meta_field_options”. It must be set to allow NULLS in order to add fields. (Apparently this is only an issue on windows installations)
The call to reorder the fields by drag n drop uses a hardcoded table name in the query, so if you use a different table prefix, the sorting will not work. To fix this, edit the file “verve-meta-boxes.php” and add the line “global $field_table_name;” below line 52, and Edit line 63/64 to read:
$query = “UPDATE `$field_table_name` SET `verve_meta_field_sequence` = $position WHERE `verve_meta_field_id` = $item”;
I have let the developer know about these and he has told me they will be fixed. Sweeeet!
When creating a custom taxonomy, the Hierarchical option determines if it will act similarly to a tag or category. In other words, if Hierarchical = False (default) then the taxonomy will display like this (like tags):
If Hierarchical = True then the taxonomy will display like this (like categories):
- In order for the custom post type to appear for the Verve Meta Boxes, you need to make sure you have checked Custom Fields under the Advanced Options for the post type. If you don’t want the custom fields to be displayed to the user entering the products, you can always uncheck it AFTER you have created the Meta Box.
And thats all folks. Hope this helped you create some awesome CMS functionality in your WordPress sites.