Skip to content

Instantly share code, notes, and snippets.

@9ete
Last active August 29, 2015 14:07
Show Gist options
  • Save 9ete/04f63e2d5c736fc8e1e6 to your computer and use it in GitHub Desktop.
Save 9ete/04f63e2d5c736fc8e1e6 to your computer and use it in GitHub Desktop.
WordPress Custom Post Type Generic Function, w/ pass in vars
/**
* Custom Post Types
*
**/
function lm_custom_post_type_creator($post_type_name, $description, $public, $menu_position, $supports, $has_archive, $irreg_plural) {
if ($irreg_plural) {$plural = 's';} else {$plural = '';}
$labels = array(
'name' => _x( $post_type_name, 'post type general name' ),
'singular_name' => _x( $post_type_name, 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New '.$post_type_name),
'edit_item' => __( 'Edit '.$post_type_name ),
'new_item' => __( 'New '.$post_type_name ),
'all_items' => __( 'All '.$post_type_name.$plural ),
'view_item' => __( 'View'.$post_type_name ),
'search_items' => __( 'Search'.$post_type_name.$plural ),
'not_found' => __( 'No '.$post_type_name.$plural.' found' ),
'not_found_in_trash' => __( 'No '.$post_type_name.$plural.' found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => $post_type_name
);
$args = array(
'labels' => $labels,
'description' => $description,
'public' => $public,
'menu_position' => $menu_position,
'supports' => $supports,
'has_archive' => $has_archive,
);
register_post_type( $post_type_name, $args );
}
add_action( 'init', lm_custom_post_type_creator('Staff', 'Holds our staff specific data', true, 5, array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), true, false));
add_action( 'init', lm_custom_post_type_creator('Testimonial', 'Holds our testimonials', true, 4, array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), true, true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment