Created
May 1, 2017 11:02
-
-
Save jamiemitchell/d10c633ed306ffabce18dfe2b0c287b7 to your computer and use it in GitHub Desktop.
Custom Post Type and Taxonomy registration example for WordPress
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
<?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