Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiemitchell/d10c633ed306ffabce18dfe2b0c287b7 to your computer and use it in GitHub Desktop.
Save jamiemitchell/d10c633ed306ffabce18dfe2b0c287b7 to your computer and use it in GitHub Desktop.
Custom Post Type and Taxonomy registration example for WordPress
<?php
/* Register Custom Post Type */
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'case-study',
array(
'labels' => array(
'name' => __( 'Case Studies' ),
'singular_name' => __( 'Case Study' )
),
'public' => true,
'has_archive' => true,
'show_in_admin_bar' => true,
'show_ui' => true,
)
);
}
/* Register Custom Taxonomy */
add_action( 'init', 'create_case_study_taxonomies', 0 );
function create_case_study_taxonomies()
{
register_taxonomy('case-study-category','case-study',array(
'hierarchical' => true,
'label' => 'Category',
'query_var' => true,
'rewrite' => array( 'slug' => 'category' ),
));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment