functions.php
/*////////////////////////////////////////////////
//
// Custom Taxonomy -> Guide Categories
// Custom Post Type -> Guide
//
////////////////////////////////////////////////*/
function guide_taxonomy() {
register_taxonomy(
'guide_category', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'guide', //post type name
array(
'hierarchical' => true,
'label' => 'Guide Categories', //Display name
'show_admin_column' => true,
'query_var' => true,
'show_in_rest' => true, //Enabling guide categories Gutenberg editor.
'rewrite' => array(
'slug' => 'guide', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action( 'init', 'guide_taxonomy');
function create_guide_post_type() {
$labels = array(
'name' => esc_html__( 'Guides', 'pmo' ),
'singular_name' => esc_html__( 'Guide', 'pmo' ),
'add_new_item' => esc_html__( 'Add New Guide', 'pmo' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'guides'),
'menu_icon' => 'dashicons-book-alt',
'supports' => array('title','editor','thumbnail','excerpt','page-attributes'),
'publicly_queryable' => true,
'show_in_rest' => true, //Enabling Gutenberg editor. No plugin needed for classic editor!
);
register_post_type('guide', $args);
}
add_action('init', 'create_guide_post_type');