Post Type Generator

Home » WordPress Generators » Custom Post Type Generator

Create and customize a WordPress custom post type (CPT) with this generator, including choosing which fields to display and setting custom labels and descriptions. With just a few clicks, you can easily create custom post types like products, events, reviews, and more. Instead of spending hours coding custom post types from scratch, you can use the WPTurbo generator to quickly create them. And because our generator is fully compatible with the latest version of WordPress, you can be confident that your CPT will work seamlessly with your website.

The name of the function that will be created.
Child Theme Support
Allow child themes to override this function.
Text domain translation file name.
The post type key, must be unique and consist of letters, numbers, and underscores. Up to 20 characters.
The post type description.
The post type singular name.
The post type plural name.
Hierarchical
Whether the post type is hierarchical (e.g. pages).
Title
Content (editor)
Excerpt
Author
Comments
Trackbacks
Revisions
Custom Fields
Page Attributes
Post Formats
Link your post type to this taxonomy.
Public
Whether the post type shoulld be queryable on the Admin UI and front-end.
Show in Admin Sidebar
Whether to show the post type in the Admin Bar.
The position in the menu order the post type should appear.
Show in Admin Bar
Whether to show the post type in the Admin Bar.
Show UI
Whether to generate a default UI for managing this post type.
Show in Navigation Menus
Whether to make this post type available for selection in navigation menus.
The icon to display in the admin sidebar and menu for this post type.
Publicly Queryable
Whether queries can be performed on the front end as part of parse_request().
Use Custom Query Var
Whether this post type should use a custom query var. Default is post type key. Example: WP_Query( array( ‘post_type’ => ‘my_type‘ ) )
The custom query var to use for this post type.
Enable Archives
Whether to enable post type archives.
Use Custom Archive Slug
Whether to use a custom slug for this post type’s archive. Default is post type key.
The custom slug to use for this post type’s archive.
Enable Export
Whether to enable post type export.
Use Custom Capabilities
Set custom management capabilities for this post type.
The base capability type to use for this post type.
The capability required to read this post type.
The capability required to read private posts of this post type.
The capability required to publish posts of this post type.
The capability required to delete posts of this post type.
The capability required to edit post of this post type.
The capability required to edit posts of this post type.
The capability required to edit posts of other users of this post type.
Show in REST API
Whether to show this post type in the REST API.
The base to use for this post type in the REST API.
The controller class to use for this post type in the REST API. Default: WP_REST_Posts_Controller.

Here some WordPress custom post types examples that you can use for your website. You can clone and edit them to fit your project (create an account first or login).

                    function wpturbo_register_my_custom_post_type(){
	$labels = array(
		'name' => _x('My Post Types', 'Post Type General Name', 'wpturbo'),
		'singular_name' => _x('My Post Type', 'Post Type Singular Name', 'wpturbo'),
		'menu_name' => __('Items', 'wpturbo'),
		'name_admin_bar' => __('Items', 'wpturbo'),
		'archives' => __('Items Archives', 'wpturbo'),
		'attributes' => __('Items Attributes', 'wpturbo'),
		'parent_item_colon' => __('Parent Item:', 'wpturbo'),
		'all_items' => __('All Items', 'wpturbo'),
		'add_new_item' => __('Add New Item', 'wpturbo'),
		'add_new' => __('Add New', 'wpturbo'),
		'new_item' => __('New Item', 'wpturbo'),
		'edit_item' => __('Edit Item', 'wpturbo'),
		'update_item' => __('Update Item', 'wpturbo'),
		'view_item' => __('View Item', 'wpturbo'),
		'view_items' => __('View Items', 'wpturbo'),
		'search_items' => __('Search Items', 'wpturbo'),
		'not_found' => __('Item Not Found', 'wpturbo'),
		'not_found_in_trash' => __('Item Not Found in Trash', 'wpturbo'),
		'featured_image' => __('Featured Image', 'wpturbo'),
		'set_featured_image' => __('Set Featured Image', 'wpturbo'),
		'remove_featured_image' => __('Remove Featured Image', 'wpturbo'),
		'use_featured_image' => __('Use as Featured Image', 'wpturbo'),
		'insert_into_item' => __('Insert into Item', 'wpturbo'),
		'uploaded_to_this_item' => __('Uploaded to this Item', 'wpturbo'),
		'items_list' => __('Items list', 'wpturbo'),
		'items_list_navigation' => __('Items list navigation', 'wpturbo'),
		'filter_items_list' => __('Filter items list', 'wpturbo'),
	);

	$args = array(
		'label' => __('My Post Type', 'wpturbo'),
		'description' => __('My Post Type Description', 'wpturbo'),
		'labels' => $labels,
		'supports' => array(
			'title',
			'content',
		),
		'taxonomies' => array(
		),
		'hierarchical' => false,
		'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,
		'publicly_queryable' => true,
		'exclude_from_search' => false,
		'has_archive' => true,
		'can_export' => true,
		'capability_type' => 'page',
		'show_in_rest' => true,
		'rest_base' => 'my_post_type',
		'rest_controller_class' => 'WP_REST_Posts_Controller',
	);

	register_post_type( 'my_post_type', $args );
}
add_action( 'init', 'wpturbo_register_my_custom_post_type', 0 );
                

WordPress custom post types FAQ

What are custom post types in WordPress?

In WordPress, a custom post type (CPT) is a post with a specific type of content that you create. It is a way to organize and manage your content within your WordPress site.

For example, you might want to create a custom post type for “products” if you run an online store, or a CPT for “events” if you run a website for a conference or event. Once created, it will be available in the WordPress interface like default post types (posts and pages).

What is the difference between a post and a custom post type in WordPress?

WordPress posts are one of the default post types, while a custom post type is a post with a specific type or category that you define.

Posts are typically used to publish news, articles, or other types of content, while CPT can be used to organize and manage any type of content within your WordPress site.

Often, custom post types are using a different template to render the content, as the structure is often diverse from regular articles.

How to create a custom post type in WordPress?

Creating a CPT in WordPress can be done in many ways. You can use a plugin like Custom Post Type UI to avoid to manipulate code.

Another approach is to write a snippet that uses the register_post_type function and add the code to your WordPress site (use our generator above to get the proper code).

To do so, you can create a custom plugin (recommended approach) or add the code to the functions.php file of your theme or child theme. Just be aware that if you add the code to your theme’s functions.php file, it will be lost if you switch to a different theme.

How post types are stored by WordPress?

Post types are stored in the database, along with all of the other content on your website. When you create a new post, WordPress stores the post in the wp_posts table in the database. The post_type field in this table is used to identify the type of post that is being stored.

For example, when you create a new post, the post_type field will be set to “post” by default. When you create a new custom post type, the post_type field will be set to the custom post type’s slug, which is a unique identifier that you define when you create the custom post type.

In addition to the wp_posts table, WordPress also stores post-type-specific data in other tables in the database. For example, the wp_postmeta table is used to store metadata for posts, and the wp_term_relationships table is used to store relationships between posts and categories or tags.

How custom post types interact with custom taxonomies and custom fields?

Custom taxonomies and custom fields can be used in combination with CPT to provide even more organization and flexibility for your content.

For example, you might use a custom taxonomy to classify your products by type, and then use custom fields to store data about each product, such as price, size, and color. You can then use this data to create custom templates and loops to display your products on your website, or to create custom queries using the WP Query or WordPress REST API.

Where can I learn more about custom post types registration?

You can check the WordPress official documentation and the register_post_type function reference.

Sign up to save your WordPress snippets on WPTurbo.