Skip to content

Instantly share code, notes, and snippets.

@pierre-dekode
Created May 3, 2023 05:44
Show Gist options
  • Save pierre-dekode/c934284b88ebf0a31f4e433f265c4a64 to your computer and use it in GitHub Desktop.
Save pierre-dekode/c934284b88ebf0a31f4e433f265c4a64 to your computer and use it in GitHub Desktop.
<?php
declare( strict_types=1 );
function wporg_register_my_custom_post_type() : void {
register_post_type( 'my_custom_post_type', [
'label' => __( 'My Post Type', 'wporg' ),
'labels' => [ 'name' => _x( 'My custom post type', 'Post Type General Name', 'wporg' ) ],
'supports' => [ 'title', 'editor' ],
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-admin-post',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'exclude_from_search' => false,
'has_archive' => true,
'taxonomies' => [ 'my_taxonomy' ],
'can_export' => false,
'capability_type' => 'page',
'show_in_rest' => true,
] );
register_taxonomy( 'my_taxonomy', [ 'post', 'my_custom_post_type' ], [
'labels' => [ 'name' => _x( 'My custom taxo', 'Taxonomy Name', 'wporg' ) ],
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'show_in_rest' => true,
'rewrite' => [ 'hierarchical' => true ],
] );
}
add_action( 'init', 'wporg_register_my_custom_post_type', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment