Created
July 27, 2014 02:48
-
-
Save halgatewood/d632e8000510f11819e0 to your computer and use it in GitHub Desktop.
Quickly Register Post Types, I found myself registering many of the same type of WordPress post types and create a little helper function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hg_register_type( $plural, $singular, $post_type = false, $position = 30, $supports = array('title','editor','thumbnail','author','custom-fields')) | |
{ | |
$uc_plural = ucwords($plural); | |
$uc_single = ucwords($singular); | |
$lc_plural = strtolower($plural); | |
$lc_single = strtolower($singular); | |
$pt = ($post_type) ? $post_type : $lc_single; | |
$labels = array('name' => $uc_plural,'singular_name' => $uc_single,'add_new' => 'Add New','add_new_item' => 'Add New ' . $uc_single,'edit_item' => 'Edit ' . $uc_single,'new_item' => 'New ' . $uc_single,'view_item' => 'View ' . $uc_single,'search_items' => 'Search ' . $uc_plural,'not_found' => 'No ' . $uc_plural . ' Found','not_found_in_trash' => 'No ' . $uc_plural . ' Found in Trash', 'parent_item_colon' => 'Parent ' . $uc_single . ':' ); | |
register_post_type( $pt, array ('labels' => $labels,'description' => '','publicly_queryable' => true,'exclude_from_search' => false,'map_meta_cap' => true,'capability_type' => 'post','public' => true,'hierarchical' => false,'rewrite' => array ( 'slug' => $lc_plural, 'with_front' => false, 'pages' => true, 'feeds' => $lc_plural ),'has_archive' => $lc_plural,'query_var' => $lc_plural,'supports' => $supports, 'taxonomies' => array (),'show_ui' => true,'menu_position' => $position,'menu_icon' => false,'can_export' => true, 'show_in_nav_menus' => true,'show_in_menu' => true )); | |
} | |
// USAGE | |
hg_register_type( 'Pianos', 'Piano', 'piano', 5 ); | |
hg_register_type( 'Guitars', 'Guitar', 'guitars', 5 ); | |
hg_register_type( 'Accessories', 'Accessory', false, 5 ); | |
hg_register_type( 'Testimonials', 'Testimonial', false, 25 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment