add_action( 'init', function() {
// Post Type
$args = [
'labels' => [ 'name' => 'Custom Items', 'singular_name' => 'Custom Item' ],
'menu_icon' => 'dashicons-admin-site',
'supports' => [ 'title', 'editor', 'thumbnail' ],
'rewrite' => [ 'slug' => 'custom_item' ],
'has_archive' => true,
'show_in_menu' => true,
'show_ui' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'can_export' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'show_in_rest' => false,
'public' => true,
'capability_type' => 'post',
];
register_post_type( 'custom_item', $args );
// Post Type Category
$args = [
'labels' => [ 'name' => 'Custom Categories', 'singular_name' => 'Custom Category' ],
'hierarchical' => true,
'rewrite' => [ 'slug' => 'custom_category' ],
'show_ui' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'show_admin_column' => false,
'query_var' => true,
'show_in_rest' => false,
];
register_taxonomy( 'custom_category', [ 'custom_item' ], $args );
} );
Register custom post types
Registers a custom post type with a category. Must be set to run everywhere.
How to use
- Log into a staging, development, or locally hosted clone of your site
- Install and activate Code Snippets
- WP Admin > Snippets > Add New
- Copy and paste the code from the Description tab above
- Check to ensure formatting came over properly and no syntax errors show up in the editor
- Customize the code as desired
- Add a meaningful title
- Select whether to run on front-end or back-end (or both)
- Click “Save and Activate”
- Test your site to ensure it works
- Disable if any problems, or recover
- Repeat for live environment
License
All code snippets are licensed GPLv2 (or later) matching WordPress licensing.
Disclaimer of warranty:
Except when otherwise stated in writing the copyright holders and/or other parties provide the program as-is without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose.
Support
- Describe the issue and what you’ve observed.
- Describe your expected outcome(s).
- List steps to reproduce the issue.
- Optionally provide screen-shot or video URLs.
