Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Tsunamijaan/7c11d47146b2baeb14f9179b0b5f2f3c to your computer and use it in GitHub Desktop.
Save Tsunamijaan/7c11d47146b2baeb14f9179b0b5f2f3c to your computer and use it in GitHub Desktop.
Register custom post & custom taxonomy in wordpress
Register custom post type
add_action( 'init', 'my_theme_custom_post' );
function my_theme_custom_post() {
register_post_type( 'cpt',
array(
'labels' => array(
'name' => __( 'CPTs' ),
'singular_name' => __( 'CPT' )
),
'supports' => array('title', 'editor', 'custom-fields', 'thumbnail', 'page-attributes'),
'public' => true
)
);
}
Register custom taxonomy ================
function my_theme_custom_post_taxonomy() {
register_taxonomy(
'cpt_cat',
'cpt',
array(
'hierarchical' => true,
'label' => 'CPT Category',
'query_var' => true,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'cpt-category',
'with_front' => true
)
)
);
}
add_action( 'init', 'my_theme_custom_post_taxonomy');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment