How to use: Easy-WordPress-Custom-Post-Types PHP class

An easy way to make: 1) custom post types 2) custom taxonomies 3) custom meta boxes in WordPress.

Get the class Here

Add it in your functions.php file.

require "assets/jw_custom_posts.php";

Custom post types

It works pretty much the same as the original function, it take two parameters. Here’s the original.

register_post_type( $post_type, $args )

And here’s the class at work. We’ll create a “Works” post type for our portfolio.

$works = new JW_Post_Type('Work', array(
    // What fields and preset metaboxes it supports
   'supports'      => array('title', 'editor', 'author', 'revisions', 'page-attributes'),
   // Hierarchical means it behaves like pages, default to false
   'hierarchical'  => true,
   // 5 is just under posts, 0 is above Dashboard
   'menu_position' => 2

See all the parameters it takes from WordPress Codex.

Custom taxonomies

Custom taxonomies are easy as a breeze also.


That creates a non hierarchical taxonomy, the tagging interface. What if you want it to be hierarchal? And just adding s in the end of Difficulty does not make it plural. You can pass as many arguments to it as you like and the second parameter is the plural name of the taxonomy.

$works->add_taxonomy('Difficulty', 'Difficulties', array(
    'hierarchical' => true

See Codex for all the parameters it takes.

Custom meta boxes

It’s a simple as:

$works->add_meta_box('Snippet Info', array(
    'GitHub Link'      => 'text',
    'Additional Notes' => 'textarea',
    'Original Snippet' => 'checkbox',
    'Snippet Image'    => 'file',
    'Favorite Food'    => array( 'select', array('pizza', 'tacos') )

You don’t have control over the HTML that is inside the boxes, but doing them like this is really easy! You can get them up and running in just few minutes. If you want more control over the boxes consider using the WP Alchemy MetaBox class.


Club-Mate, the beverage →