Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WordSesh 2 Creatively Creating Custom Post Types

Nikhil Vimal
December 07, 2013

WordSesh 2 Creatively Creating Custom Post Types

This presentation was presented at WordSesh 2. This presentation is about extending the power of Custom Post Types.

Nikhil Vimal

December 07, 2013
Tweet

More Decks by Nikhil Vimal

Other Decks in Programming

Transcript

  1. Hi, I’m Nikhil (NikV) • I develop with WordPress •

    I can be found on Twitter @TechVoltz • Core contributor for WordPress 3.7
  2. Create a file called myposttype.php <?php /** * Plugin Name:

    Your Custom Post Type plugin * Plugin URI: http://yourpluginswebsite.com * Description: A brief description of your Plugin. * Version: The Plugin's Version Number, e.g.: 1.0 * Author: Your Name * Author URI: http://yourwebsite.com * License: A "Slug" license name e.g. GPL2 */
  3. add_action('init', 'wordsesh_sessions'); function wordsesh_sessions() { $wordsesh_args = array( 'public' =>

    true, 'query_var' => 'wordsesh', ‘can_export’ => true, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'page-attributes' ), 'labels' => array( 'name' => 'WordSesh 2 Sessions', 'singular' => 'WordSesh 2 Session', 'add_new' => 'Add Session', 'add_new_item' => 'Add Session', 'edit_item' => 'Edit Session', 'new_item' => 'New Session', 'view_item' => 'View Session', 'search_items' => 'Search Sessions', 'not_found' => 'No sessions found', 'not_found_in_trash' => 'No Sessions found in the Trash', ), ); register_post_type('WordSesh', $wordsesh_args ); }
  4. Let’s add a meta box function add_cpt_metabox(){ add_meta_box('cpt_meta', 'Speaker Meta

    Box', 'cpt_meta', 'wordsesh','side', 'default'); } add_action('add_meta_boxes', 'add_cpt_metabox');
  5. 'labels' => array( 'name' => 'Tracks', 'edit_item' => 'Edit Track',

    'update_item' => 'Update Track', 'add_new_item' => 'Add New Track', 'new_item_name' => 'New Track', 'all_items' => 'All Tracks', 'search_items' => 'Search Tracks', 'popular_items' => 'Popular Tracks', 'add_or_remove_items' => 'Add or remove Tracks', 'choose_from_most_used' => 'Choose from most used Tracks', ), );