How to add ccustome post type in wordpress


Today we will learn how to add custom post type in wordpress backend. you can use this into your themes code or develop a plugin for this.

This can be added direct to your functions,php file or you can include an external file that contains this code to your functions.php

Step 1: The below code will add the Custom menu section and the editor section of it.

< ?php add_action('init', 'portfolio_register'); function portfolio_register() { $labels = array( 'name' => _x(‘Portfolio’, ‘post type general name’),
‘singular_name’ => _x(‘Portfolio Item’, ‘post type singular name’),
‘add_new’ => _x(‘Add New’, ‘Portfolio item’),
‘add_new_item’ => __(‘Add New Portfolio Item’),
‘edit_item’ => __(‘Edit Portfolio Products Item’),
‘new_item’ => __(‘New Portfolio Item’),
‘view_item’ => __(‘View Portfolio Item’),
‘search_items’ => __(‘Search Portfolio’),
‘not_found’ => __(‘Nothing found’),
‘not_found_in_trash’ => __(‘Nothing found in Trash’),
‘parent_item_colon’ => ”

$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_icon’ => get_stylesheet_directory_uri() . ‘/includes/icon_03.png’,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)

register_post_type( ‘Portfolioproducts’ , $args );


step 2:The next code will add the texonomy or category for you custome posts


< ?php register_taxonomy("Products", array("Portfolio"), array("hierarchical" => true, “label” => “Portfolio Category”, “singular_label” => “Portfolio Category”, “rewrite” => true)); ?>


Here is everything is complete you can use this , but the next code is for those who want to add more fields or textareas in the custome post types these you can call as custome fields.

Step 3 :

< ?php add_action("admin_init", "admin_init"); function admin_init(){ add_meta_box("credits_meta", "Shipping Options & Price", "credits_meta", "Portfolio", "normal", "low"); } function credits_meta() { global $post; $custom = get_post_custom($post->ID);
$shipping_quantiity = $custom[“shipping_quantity”][0];
$shipping_price = $custom[“shipping_price”][0];
$book_price = $custom[“book_price”][0];

Book Price: How to call this custom post type at the front end into your file

© 2020 IT Tech Developer | XML Sitemap | HTML Sitemap
Powered by T-Developers | Designed by: Shah Rukh | Thanks to Friends
rss Follow on Twitter facebook linkedin youtube google+ email