lucbord
2/5/2016 - 5:18 PM

multiple custom post types registration

multiple custom post types registration

function ntg_register_post_type( $title, $args = array() ){
     
    $sanitizedTitle = sanitize_title( $title );
     
    $defaults = array(
            'labels' => array(
                'name' => $title . 's',
                'singular_name' => $title,
                'add_new_item' => 'Add New ' . $title,
                'edit_item' => 'Edit ' . $title,
                'new_item' => 'New ' . $title,
                'search_items' => 'Search ' . $title . 's',
                'not_found' => 'No ' . $title . 's found',
                'not_found_in_trash' => 'No ' . $title . 's found in trash'
            ),
            '_builtin' => false,
            'public' => true,
            'hierarchical' => false,
            'taxonomies' => array( ),
            'query_var' => true,
            'menu_position' => 6,
            'supports' => array( 'title', 'editor', 'thumbnail', 'author', 'comments', 'genesis-seo' ),
            'rewrite' => array( 'slug' => $sanitizedTitle ),
            'has_archive' => true
        );
     
    $args = wp_parse_args( $args, $defaults );
     
    $postType = isset( $args['postType'] ) ? $args['postType'] : $sanitizedTitle;
     
    register_post_type( $postType, $args );
     
}


 

$postTypes = array(
    'Staff'               => '',
    'Bar'               => array( 'has_archive' => false ),
    'Nick\'s Peeps'     => array( 'postType' => 'geeks', rewrite => array( 'slug' => 'geek' ) )
);
 
foreach( $postTypes as $title => $args )
    ntg_register_post_type( $title, $args );