Revision: 54493
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 29, 2011 23:26 by i-am-andy
Initial Code
/** -------------- ADD CUSTOM POST TYPES ----------------- **/
// The register_post_type() function is not to be used before the 'init'.
add_action( 'init', 'my_custom_init' );
/* Here's how to create your customized labels */
function my_custom_init() {
$labels = array(
'name' => _x( 'Case Studies', 'post type general name' ), // Tip: _x('') is used for localization
'singular_name' => _x( 'Case Study', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Case Study' ),
'edit_item' => __( 'Edit Case Study' ),
'new_item' => __( 'New Case Study' ),
'view_item' => __( 'View Case Study' ),
'search_items' => __( 'Search Case Studies' ),
'not_found' => __( 'No Case Studies found' ),
'not_found_in_trash' => __( 'No Case Studies found in Trash' ),
'parent_item_colon' => ''
);
// Create an array for the $args
$args = array( 'labels' => $labels, /* NOTICE: the $labels variable is used here... */
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => null,
'has_archive' => true,
'rewrite' => true,
'taxonomies' => array( 'Project Type' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'page-attributes' )
);
register_post_type( 'case-studies', $args ); /* Register it and move on */
}
/** -------------- REGISTER CUSTOM TAXONOMIES ----------------- **/
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_casestudies_taxonomies', 0 );
//create two taxonomies, genres and writers for the post type "book"
function create_casestudies_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Project Type', 'taxonomy general name' ),
'singular_name' => _x( 'Project Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Project Types' ),
'all_items' => __( 'All Project Types' ),
'parent_item' => __( 'Parent Project Type' ),
'parent_item_colon' => __( 'Parent Project Type:' ),
'edit_item' => __( 'Edit Project Type' ),
'update_item' => __( 'Update Project Type' ),
'add_new_item' => __( 'Add New Project Type' ),
'new_item_name' => __( 'New Project Type Name' ),
'menu_name' => __( 'Project Type' ),
);
register_taxonomy('genre',array('case-studies'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'project' ),
));
}
Initial URL
Initial Description
Register a Custom Post Type and a Custom Taxonomy in Wordpress
Initial Title
Wordpress register Custom Post Type and Custom Taxonomy
Initial Tags
post, wordpress
Initial Language
PHP