How to create custom post type in WordPress

WordPress comes with some default post type. Those are reserved in WordPress. Here are those reserved post types that comes with WordPress.

  • post
  • page
  • attachment
  • revision
  • nav_menu_item
  • custom_css
  • customize_changeset
  • oembed_cache
  • user_request
  • wp_block

You can create your own post type. Creating a post type in WordPress is nothing but a simple block of code. You just need to define your post type name and some array or string of arguments to register custom post type.

register_post_type('your-post-type-name', array());

You need to pass your arguments as second parameter inside register_post_type function. Here are some basic arguments to create a custom post type.

    'labels' => array(
        'name' => __( 'Pizza' ),
        'singular_name' => __( 'Pizza' )
    'supports' => array( 'title', 'thumbnail', 'revisions', 'custom-fields' ),
    'public' => true,
    'has_archive' => true,
    'rewrite' => array('slug' => 'pizza'),
    'show_in_rest' => true,

Here are some basic arguments to create a custom post type named pizza. Inside labels key you can define your post type name and singular name. supports key holds a array of what things you need to support to create a post for Pizza. If you need to open your data through rest API of WordPress, you need to set value as true of show_in_rest key. You also need to define the slug name of your custom post type inside rewrite key.

If you want to dig deep for custom post type, here is the codex documentation link.