Welcome to Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy

Create Custom Post Type in WordPress

Create mu-plugins folder in wp-content

Create plugin.php file in mu-plugins add following code in that file

				
					<?php

/*
 * Plugin Name: Content Management
 * Description: Custom Posts and taxonomies, Custom metablocks and APIs.
 * Version: 1.0.0
 * Author: Praful
 * Author URI: https://prafulbhuskute.com  
*/


				
			

now link your custom post type in plugin.php

				
					<?php

/*
 * Plugin Name: Content Management
 * Description: Custom Posts and taxonomies, Custom metablocks and APIs.
 * Version: 1.0.0
 * Author: Praful
 * Author URI: https://prafulbhuskute.com  
*/

// CUSTOM POST TYPES
require_once __DIR__ . '/content-management/custom-post-types/product.php';
				
			

Creating a function to create our Custom Post type (Product)

				
					<?php 


/*
* Creating a function to create our Custom Post type (Product)
*/
add_action( 'init', 'product_custom_post_type', 0 );
 

function product_custom_post_type() {
 
    // Set UI labels for Custom Post Type
        $labels = array(
            'name'                => __( 'Products'),
            'singular_name'       => __( 'Product' ),
            'menu_name'           => __( 'Products' ),
            'parent_item_colon'   => __( 'Parent Product' ),
            'all_items'           => __( 'All Products' ),
            'view_item'           => __( 'View Product' ),
            'add_new_item'        => __( 'Add New Product' ),
            'add_new'             => __( 'Add New' ),
            'edit_item'           => __( 'Edit Product' ),
            'update_item'         => __( 'Update Product' ),
            'search_items'        => __( 'Search Product' ),
            'not_found'           => __( 'Not Found' ),
            'not_found_in_trash'  => __( 'Not found in Trash' ),
        );
         
    // Set other options for Custom Post Type
    
        $args = array(
            'label'               => __( 'product' ),
            'description'         => __( 'Product' ),
            'labels'              => $labels,
            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', ),
            'taxonomies'          => array( 'genres' ),
            'hierarchical'        => false,
            'public'              => true,
            'show_ui'             => true,
            'menu_icon'           => 'dashicons-products',
            'show_in_menu'        => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => true,
            'menu_position'       => 99,
            'can_export'          => true,
            'has_archive'         => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
            'capability_type'     => 'post',
            'show_in_rest'        => true,
        );
         
        // Registering your Custom Post Type
        register_post_type( 'product', $args );
     
    }

				
			

Creating a function to create our Custom Taxonomies for Prodcuts

				
					<?php

add_action( 'init', 'create_delivery_category', 0 );
 

function create_delivery_category() {
 
  $labels = array(
    'name'              => _x( 'Delivery', 'taxonomy general name' ),
    'singular_name'     => _x( 'Delivery', 'taxonomy singular name' ),
    'search_items'      => __( 'Search Delivery' ),
    'all_items'         => __( 'All Delivery' ),
    'parent_item'       => __( 'Parent Delivery' ),
    'parent_item_colon' => __( 'Parent Delivery:' ),
    'edit_item'         => __( 'Edit Delivery' ), 
    'update_item'       => __( 'Update Delivery' ),
    'add_new_item'      => __( 'Add New Delivery' ),
    'new_item_name'     => __( 'New Delivery Name' ),
    'menu_name'         => __( 'Delivery' ),
  );    
 
  $args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_in_rest'      => true,
    'show_admin_column' => true,
    'query_var'         => true,
  );

// Now register the taxonomy
  register_taxonomy('delivery','product', $args);
 
}
				
			

Drop your queries

Table of Contents

Have A Project In Mind? Let's Get To Work