[DFBM - Register CPT]
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 | |
// This is the right way to register your taxonomies to work fine with DFBM | |
function register_my_cpt() | |
{ | |
$args = array( | |
'label' => 'Example CPT', | |
'public' => true, | |
'show_ui' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'rewrite' => array('slug' => 'example-cpt'), | |
'query_var' => true, | |
'menu_icon' => 'dashicons-video-alt', | |
'supports' => array( | |
'thumbnail','title', 'editor', 'excerpt','author', 'revisions', 'custom-fields',), | |
); | |
register_post_type( 'example-cpt', $args ); | |
} // end register_my_cpt | |
register_my_cpt(); | |
register_taxonomy( | |
'example-cpt-cat', // "cat" must anywhere be included in your slug | |
array( 'example-cpt' ), | |
array( | |
'hierarchical' => true, | |
'label' => 'Categories', | |
'singular_label' => 'Category', | |
'rewrite' => array( 'slug' => 'example-cpt', 'with_front'=> false ) | |
) | |
); | |
register_taxonomy( | |
'example-cpt-tag', // "tag" must anywhere be included in your slug | |
array( 'example-cpt' ), | |
array( | |
'hierarchical' => false, | |
'label' => 'Tags', | |
'singular_label' => 'Tag', | |
'rewrite' => array( 'slug' => 'example-cpt', 'with_front'=> false ) | |
) | |
); | |
// More infos: https://codex.wordpress.org/Function_Reference/register_taxonomy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment