• Facebook Icon Link
    • Instagram Icon Link

    How to Make a WordPress Custom Post Type.


    make wordpress custom post type

    Tutorial Overview.

    This tutorial will explain how to make a WordPress custom post type. I will explain how to make one with a plugin, how to make one programmatically and I will review a few WordPress plugins that you may want to use.

    Quickies.

    What is a WordPress Post?

    A WordPress post holds and displays different types of content on your website. Many people think of a WordPress post as a blog entry and it is but there are other types of posts in WordPress, like a page. A blog post and a page each have many different characteristics but they are both a type of post. Both of these post types come default in WordPress (among others) but WordPress also gives us the ability to create our own post types. This tutorial will show you how to make your own custom post type.

    How do I Make a WordPress Custom Post Type?

    There are two ways to make your own custom post type: You can use a plugin or you can do it with code. If you are technically inclined you can drop in a little bit of code and be done with it. If you would rather not dig into the code there are many WordPress plugins that will do it for you.

    What is the Best Plugin to Create a WordPress Custom Post Type?

    Here are my picks for the best custom post type plugins for WordPress:

    Custom Post Type UI Logo

    Custom Post Type UI

    This is one of the most popular custom post type plugins and it is free. With this plugin, you will be able to create your own post types and taxonomies. It will also let you edit the existing post types on your website and import and export data. This plugin will not display your custom post types but they do offer an extension called CPT UI Extended Features that you can purchase for about 30 bucks. It is well worth the money. The CPT UI Extended Features plugin gives you many very nice layouts to display your new custom post type.

    Custom Post Types and Custom Fields WCK

    Custom Post Types and Custom Fields – WCK

    This is another free plugin to create custom post types in WordPress. This plugin lets you create post types, custom taxonomies, custom fields and metaboxes. It has a large selection of custom field types available. This plugin also has an extension that has repeater fields, front-end templates, front-end posting and many other benefits. The extension is called WordPress Creation Kit by Cozmoslabs and is about 50 bucks.

    Toolset Types Logo

    Toolset Types

    This is a very popular WordPress plugin to create custom post types, custom fields, and taxonomies. I have only used this plugin a few times but it seems to be a very robust plugin that will do almost anything you need it to with custom post types. It is more complex than the other plugins listed here but the documentation and support seem to be plentiful. There will probably be a bit of a learning curve with this one.

    Pods Custom Content Types and Fields Logo

    Pods – Custom Content Types and Fields

    The Pods plugin gives you the ability to create custom post types, taxonomies, fields and extend WordPress objects like pages, users and posts. You can display your content with shortcodes, widgets or they have a code-free template solution if needed. This is a great plugin and it seems to have good support behind it.

    How to Create a WordPress Custom Post Type Programmatically.

    I prefer this method of adding custom post types to WordPress because I like to keep my plugins to a minimum. Add this code to your website in the functions.php file. Make sure you are editing the functions.php file in the child theme otherwise your code will be overwritten when you update WordPress. More info here: How to Make a WordPress Child Theme.

    There are a few ways to access the functions.php file. Here are a couple simple ways:

    Add Custom Post Type Code to the functions.php File Via FTP:

    1. Make an FTP connection to your web server. Instructions if needed: How to Make an FTP Connection.
    2. The functions.php file is located here: wp-content > themes > #your child theme# > functions.php.
    3. Open the functions.php file in a text editor like Notepad++ or similar.
    4. Modify the code below to fit your specific custom post type or use a code generator like WPHasty.com.
    5. Copy and paste the code into the functions.php file.

    Add Custom Post Type Code to the functions.php File Via WordPress admin:

    1. Login to the admin area of the website.
    2. Go to: Appearance > Theme Editor > #your theme# > functions.php.
    3. Modify the code below to fit your specific custom post type or use a code generator like WPHasty.com.
    4. Copy and paste the code into the functions.php file.
    // Register Custom Post Type
    function custom_post_type() {
    
    	$labels = array(
    		'name'                  => _x( 'Post Types', 'Post Type General Name', 'text_domain' ),
    		'singular_name'         => _x( 'Post Type', 'Post Type Singular Name', 'text_domain' ),
    		'menu_name'             => __( 'Post Types', 'text_domain' ),
    		'name_admin_bar'        => __( 'Post Type', 'text_domain' ),
    		'archives'              => __( 'Item Archives', 'text_domain' ),
    		'attributes'            => __( 'Item Attributes', 'text_domain' ),
    		'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
    		'all_items'             => __( 'All Items', 'text_domain' ),
    		'add_new_item'          => __( 'Add New Item', 'text_domain' ),
    		'add_new'               => __( 'Add New', 'text_domain' ),
    		'new_item'              => __( 'New Item', 'text_domain' ),
    		'edit_item'             => __( 'Edit Item', 'text_domain' ),
    		'update_item'           => __( 'Update Item', 'text_domain' ),
    		'view_item'             => __( 'View Item', 'text_domain' ),
    		'view_items'            => __( 'View Items', 'text_domain' ),
    		'search_items'          => __( 'Search Item', 'text_domain' ),
    		'not_found'             => __( 'Not found', 'text_domain' ),
    		'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
    		'featured_image'        => __( 'Featured Image', 'text_domain' ),
    		'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
    		'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
    		'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
    		'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
    		'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
    		'items_list'            => __( 'Items list', 'text_domain' ),
    		'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
    		'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
    	);
    	$args = array(
    		'label'                 => __( 'Post Type', 'text_domain' ),
    		'description'           => __( 'Post Type Description', 'text_domain' ),
    		'labels'                => $labels,
    		'supports'              => false,
    		'taxonomies'            => array( 'category', 'post_tag' ),
    		'hierarchical'          => false,
    		'public'                => true,
    		'show_ui'               => true,
    		'show_in_menu'          => true,
    		'menu_position'         => 5,
    		'show_in_admin_bar'     => true,
    		'show_in_nav_menus'     => true,
    		'can_export'            => true,
    		'has_archive'           => true,
    		'exclude_from_search'   => false,
    		'publicly_queryable'    => true,
    		'capability_type'       => 'page',
    	);
    	register_post_type( 'post_type', $args );
    
    }
    add_action( 'init', 'custom_post_type', 0 );
    

    Be sure to save the changes. You should now be able to see your new custom post type in the admin area of your website.

    Explaination of the WordPress Custom Post Type Code.

    The code above creates a custom post type. The register_post_type() function receives two main parameters. The first parameter is required and defines the name of the post type. The second parameter is an array of arguments that define specific details about your custom post type. The labels array defines all of the different labels for your custom post type. The description option is a short explanation of what your custom post type is and does. The menu_position sets the location in the backend menu of your custom post type. For example, setting this to 5 places it below the regular Posts menu item. You can adjust this number to raise or lower it in the menu. The supports option is a very important setting because it tells WordPress what capabilities your custom post type will have. More info: WordPress custom post types.

    How to See Your WordPress Custom Posts in Action.

    You will be able to view the archive page of your custom posts at https://yourdomain.com/yourcustomposttype/.

     

    Additional Posts.

    1 comment
    1. vert-shock.org/
      vert-shock.org/
      April 25, 2020 at 6:43 pm

      I’m certainly going to investigate it. Truly exceptionally valuable tips are given here. Much obliged to you to such an extent. Keep up the benevolent acts.

      Reply
    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Pin It on Pinterest

    Share This