Skip to content

This class makes the process of creating WordPress custom post types, taxonomies, and custom meta boxes as easy as possible. It's still unfinished.

Notifications You must be signed in to change notification settings

Kudratullah/Easy-WordPress-Custom-Post-Types

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 

Repository files navigation

Usage

Firstly, this class requires PHP 5.3. Make sure you have it running.

Secondly, this is still quite new, so it needs a lot of debugging and work. :) In other words, it's Beta.

First, download the class, and drag it into the root of your theme directory.

Next, within functions.php, require the class.

require 'jw_custom_posts.php';

You now have access to the class and its functions. Instantiate the class. We'll use a Snippet post type as an example.

$snippet = new JW_Post_Type('Snippet');

You may also pass an optional second parameter to override some of the defaults. For example, if I only want to provide support for a title and an excerpt, I could do:

$snippet = new JW_Post_Type('Snippet', array(
   'supports' => array('title', 'excerpt')
);

If I want to also use the built-in category and/or tag taxonomies that WordPress provides...

$snippet = new JW_Post_Type('Snippet', array(
   'taxonomies' => array('category', 'post_tag')
);

Custom Taxonomies

It makes sense to filter our sample Snippet post type by difficulty and language. We can implement that functionality quite easily.

$snippet->add_taxonomy('Difficulty');
$snippet->add_taxonomy('Language');

I may also specify the plural form of my taxonomy, and any optional overrides.

$snippet->add_taxonomy('Difficulty', 'Difficulties', array(
  'show_ui' => false
);

Meta Boxes

Our Snippet post type should allow me to enter additional information about the single snippet - perhaps a GitHub link, additional notes, an associated url for the snippet, etc. These items are unique to each post, and can be displayed in a custom meta box.

$snippet->add_meta_box('Snippet Info', array(
  'Associated URL' => 'text',
  'GitHub Link' => 'text',
  'Additional Notes' => 'textarea',
  'Original Snippet' => 'checkbox',
  'Snippet Image' => 'file'
));

Within the second array argument, set the label text and the type of input to display, respectively. The available input choices are:

  • text
  • textarea
  • checkbox
  • file (for uploading images and files),
  • select (for dropdown)

However, if you require a select box, you need to pass an array, with the first key equaling the type of input to create ('select' element), and the second key being an array of choices. For example:

$snippet->add_meta_box( 'Personal Info', array(
  'Name' => 'text',
  'Bio'  => 'textarea'
  'Favorite Food' => array( 'select', array('pizza', 'tacos') )
);

About

This class makes the process of creating WordPress custom post types, taxonomies, and custom meta boxes as easy as possible. It's still unfinished.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published