Themergency fooplugins.com

Better WordPress Custom Post Types

| 14 Comments

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

  1. 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:
  2. Click Add New under the Custom Post Types menu and enter in the values for a simple Products custom post type and save it:
  3. Then add a new Custom Taxonomy Brands and save it (make sure to Select TRUE for Hierarchical) :
  4. You will notice some new admin menu options:
  5. Under tools, click Verve Meta Boxes , then create a new meta box:
  6. Then add any fields you might want to capture for your products:
  7. Then add products, and you will notice a nice new box where you can specify the product info:
  8. 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.

Problems

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!

Other Notes

  • 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.

9 comments
  Livefyre
  • Get Livefyre
  • FAQ
MickaelHoudebert
MickaelHoudebert

Hello, thank for this step by step tutorial !!But i have a question.

I cannot write/understod php. How can we implement that in the loop php (in the wordpress template)Thanks a lot !

user

I have a problem...........i follow all your steps and it works fine, but when i add product and publish on my page is nothing shown....why?

abzal
abzal

Thank you for this post!

Brij
Brij

Nice Post!!!

I have created a project collection theme based on this custom post type feature.

See following to download:

http://www.techbrij.com/342/create-project-collection-theme-wordpress-3-custom-post-type

Safwan
Safwan

Wonderful tutorial... loved it. If you can write article about doing this in code would be great!!! Thanx

Matt

fantastic! The code way is fine but this speeds up development 1million percent!

Adam Pieniazek
Adam Pieniazek

Useful, but it's really not that much code to get this implemented by hand. Plus, once you do it once it's mostly copy & paste for future post types instead of installing and setting up all the plugins again. Still useful for clients who might want to tinker.

admin
admin

Hi Adam,
Yes I agree 100%, but for the guys out there with no coding knowledge, plugins are the only option.
I am also a lazy coder, so if I can get the final result I need out faster by using someone else's plugin, then thats the route I tend to take :)

Trackbacks

  1. [...] This post was mentioned on Twitter by Marc Forrest, Themergency. Themergency said: new blog post "Better WordPress Custom Post Types" - http://ow.ly/2cUDM [...]

  2. wp-popular.com » Blog Archive » Better WordPress Custom Post Types | Themergency says:

    [...] more: Better WordPress Custom Post Types | Themergency Tags: 3.0, [...]

  3. 30 Fresh WordPress Resources of July | DynamicWP says:

    [...] Better WordPress Custom Post Types These are steps I followed to create my better custom post [...]

  4. 60 Best Ultimate Resources For Wordpress Enthusiasts in | Wordpress Daily says:

    [...] Better WordPress Custom Post Types These are steps I followed to create my better custom post [...]

  5. Más sobre taxonomías y tipos de contenido personalizados: artículos, tutoriales, presentaciones | La Bitácora del Tigre says:

    [...] de julio de Better WordPress Custom Post Types. Tutorial muy recomendable para los usuarios noveles, porque enseña a crear un sitio basado en un [...]