Hey there! So you’re looking to create a custom post type in WordPress, huh? Well, you’ve come to the right place. Creating a custom post type is a great way to organize and present different types of content on your website. It’s also a good way to separate content from the default “post” and “page” post types that come with WordPress.

Before we begin, it’s important to note that creating a custom post type involves editing code. If you’re not comfortable with HTML, CSS, JavaScript, and PHP, I recommend finding a developer to help you out.

Now, let’s get started.

First, you’ll need to create a new PHP file and call it something like “custom-post-type.php“. This file will hold all the code for your custom post type.
In this file, you’ll want to add the following code:

<?php
function create_custom_post_type() {
    register_post_type( 'custom_post_type',
    array(
        'labels' => array(
            'name' => __( 'Custom Post Type' ),
            'singular_name' => __( 'Custom Post Type' )
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array( 'slug' => 'custom-post-type' ),
    )
    );
}
add_action( 'init', 'create_custom_post_type' );

This code will create a new post type called “custom_post_type” that is publicly viewable and has an archive page. It will also give the post type a URL slug of “custom-post-type“. You can change the name, singular name, and slug to whatever you want.

Next, you’ll want to add some custom fields to your custom post type so that it’s more useful. You can do this by using the Advanced Custom Fields plugin, or you can add the fields manually using the following code:

add_action( 'add_meta_boxes', 'add_custom_post_type_metaboxes' );
function add_custom_post_type_metaboxes() {
    add_meta_box(
        'custom_post_type_metabox',
        'Custom Post Type Metabox',
        'custom_post_type_metabox',
        'custom_post_type',
        'normal',
        'high'
    );
}

This code will add a custom metabox to your custom post type, which you can then use to add custom fields to your post type.

Finally, you’ll want to add some CSS and JavaScript to your custom post type to make it look and function the way you want. You can do this by adding the following code to your theme’s functions.php file:

function custom_post_type_scripts() {
    wp_enqueue_style( 'custom-post-type-style', get_template_directory_uri() . '/custom-post-type.css' );
    wp_enqueue_script( 'custom-post-type-script', get_template_directory_uri() . '/custom-post-type.js' );
}
add_action( 'wp_enqueue_scripts', 'custom_post_type_scripts' );

This code will add a CSS file called “custom-post-type.css” and a JavaScript file called “custom-post-type.js” to your custom post type. Make sure to create these files and place them in your theme’s directory.

Once you’ve added all of this code and created the necessary files, you can go ahead and activate your custom post type by adding the custom-post-type.php file to your theme’s functions.php file or as a separate plugin.

And that’s it! You’ve successfully created a custom post type in WordPress. Now you can use it to organize and present different types of content on your website. Just remember to be careful when editing code, and always make sure to backup your website before making any changes.

More information can be found in the documentation

Thank you for your read. Goodbye!