{"id":65023,"date":"2016-11-19T09:55:26","date_gmt":"2016-11-19T09:55:26","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=65023"},"modified":"2016-11-19T09:55:26","modified_gmt":"2016-11-19T09:55:26","slug":"create-custom-post-type-wordpress","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/","title":{"rendered":"Create Custom Post Type WordPress"},"content":{"rendered":"<p style=\"text-align: justify;\"><strong>Custom Post Type\u00a0<\/strong>is same as WordPress default post having different post type from WordPress. As we know WordPress regular post has post type &#8216;post&#8217;. So, to create our own post type WordPress provide a function named register_post_type(). This function allows us to define new post type by supported features, labels.<\/p>\n<p style=\"text-align: justify;\">\n<div class=\"alert alert-success\">\n<div>Note that you must call <strong>register_post_type()<\/strong> before the <strong>admin_menu<\/strong>\u00a0and after the <strong>after_setup_theme<\/strong>\u00a0action hooks. A good\u00a0hook to use is the <strong>init<\/strong>\u00a0hook (codex info).<\/div>\n<\/div>\n<p>Let&#8217;s start with example &#8211;<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\nfunction create_custom_post() {\r\n\r\n$args() = array();\r\n\r\nregister_post_type( 'type-name', $args );\r\n\r\n}\r\n\r\nadd_action( 'init', 'create_custom_post' );\r\n\r\n?&gt;<\/pre>\n<p>In above code, type-name in register_post_type() is the name of custom post type. Here any name can be set according to need of post type.<\/p>\n<p>To register post type according to our needs, we will go through some options and add\u00a0them to $args array. Let&#8217;s add some options (labels, features).<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\nfunction create_custom_post() {\r\n\r\n$args = array(\r\n           'labels' =&gt; array(\r\n                          'name'         =&gt; __('Name for type in admin menu'),\r\n                          'singular_name =&gt; __('Singular Name'),\r\n                          'add_new'      =&gt; __('Add New'),\r\n                       ),\r\n           'description' =&gt; 'Description about post type',\r\n           'public'      =&gt; true,\r\n           'menu_position' =&gt; 10,\r\n           'supports'    =&gt; array('title', 'editor', 'thumbnail', excerpt')\r\n         );\r\nregister_post_type( 'type-name' 'create_custom_post' );\r\n\r\n}\r\n\r\n?&gt;<\/pre>\n<h3>Labels<\/h3>\n<p style=\"text-align: justify;\">This option defines the different labels for custom post type. Foe example\u00a0we set for name, singular name, add new. There can be more also like edit, view, search, etc.<\/p>\n<h3 style=\"text-align: justify;\">Description<\/h3>\n<p style=\"text-align: justify;\">The description as name suggests contain some explanation about custom post type like what it does.<\/p>\n<h3 style=\"text-align: justify;\">Menu Position<\/h3>\n<p style=\"text-align: justify;\">In this we can define the position of post type in admin menu. The higher we set it , lower the menu will be placed.<\/p>\n<h3 style=\"text-align: justify;\">Supports<\/h3>\n<p style=\"text-align: justify;\">This option defines WordPress default controls as regular post to custom post type. For a full list take a look at the\u00a0<a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/register_post_type#Arguments\">arguments section<\/a> in the Codex.<\/p>\n<p>Reference\u00a0<a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/register_post_type\">https:\/\/codex.wordpress.org\/Function_Reference\/register_post_type<\/a>.<\/p>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<div>\n<h3 class=\"panel-title\">Support<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<div>\n<p>Still have any issue feel free to add a ticket and let us know your views to make the code better <a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\">https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/<\/a><\/p>\n<p>Thanks for Your Time! Have a Good Day!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Custom Post Type\u00a0is same as WordPress default post having different post type from WordPress. As we know WordPress regular post has post type &#8216;post&#8217;. So, to create our own post type WordPress provide a function named register_post_type(). This function allows us to define new post type by supported features, labels. Note that you must call <a href=\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":109,"featured_media":62042,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1260],"tags":[4030,4031,1258],"class_list":["post-65023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-custom-post-type","tag-post-type","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Custom Post Type WordPress<\/title>\n<meta name=\"description\" content=\"Custom Post Type is same as WordPress default post having different post type from WordPress. The function named register_post_type() is used to do this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Custom Post Type WordPress\" \/>\n<meta property=\"og:description\" content=\"Custom Post Type is same as WordPress default post having different post type from WordPress. The function named register_post_type() is used to do this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-19T09:55:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Varun Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/imVvashistha\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Varun Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\"},\"author\":{\"name\":\"Varun Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5f80f80fad3753d9bdfb065a31cc537d\"},\"headline\":\"Create Custom Post Type WordPress\",\"datePublished\":\"2016-11-19T09:55:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\"},\"wordCount\":297,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png\",\"keywords\":[\"Custom Post Type\",\"Post Type\",\"wordpress\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\",\"url\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\",\"name\":\"Create Custom Post Type WordPress\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png\",\"datePublished\":\"2016-11-19T09:55:26+00:00\",\"description\":\"Custom Post Type is same as WordPress default post having different post type from WordPress. The function named register_post_type() is used to do this.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png\",\"width\":825,\"height\":260,\"caption\":\"Custom Post Type\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create Custom Post Type WordPress\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5f80f80fad3753d9bdfb065a31cc537d\",\"name\":\"Varun Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2bf364f755500f5f58d13d0fddbeb303ae75529a58e113c5638c7d20ff48b18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2bf364f755500f5f58d13d0fddbeb303ae75529a58e113c5638c7d20ff48b18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Varun Kumar\"},\"description\":\"Inquisitive.\",\"sameAs\":[\"https:\/\/x.com\/https:\/\/twitter.com\/imVvashistha\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/varun-kumar286\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create Custom Post Type WordPress","description":"Custom Post Type is same as WordPress default post having different post type from WordPress. The function named register_post_type() is used to do this.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/","og_locale":"en_US","og_type":"article","og_title":"Create Custom Post Type WordPress","og_description":"Custom Post Type is same as WordPress default post having different post type from WordPress. The function named register_post_type() is used to do this.","og_url":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-11-19T09:55:26+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png","type":"image\/png"}],"author":"Varun Kumar","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/imVvashistha","twitter_site":"@webkul","twitter_misc":{"Written by":"Varun Kumar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/"},"author":{"name":"Varun Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5f80f80fad3753d9bdfb065a31cc537d"},"headline":"Create Custom Post Type WordPress","datePublished":"2016-11-19T09:55:26+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/"},"wordCount":297,"commentCount":4,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png","keywords":["Custom Post Type","Post Type","wordpress"],"articleSection":["WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/","url":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/","name":"Create Custom Post Type WordPress","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png","datePublished":"2016-11-19T09:55:26+00:00","description":"Custom Post Type is same as WordPress default post having different post type from WordPress. The function named register_post_type() is used to do this.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet.png","width":825,"height":260,"caption":"Custom Post Type"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/create-custom-post-type-wordpress\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Custom Post Type WordPress"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5f80f80fad3753d9bdfb065a31cc537d","name":"Varun Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2bf364f755500f5f58d13d0fddbeb303ae75529a58e113c5638c7d20ff48b18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2bf364f755500f5f58d13d0fddbeb303ae75529a58e113c5638c7d20ff48b18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Varun Kumar"},"description":"Inquisitive.","sameAs":["https:\/\/x.com\/https:\/\/twitter.com\/imVvashistha"],"url":"https:\/\/webkul.com\/blog\/author\/varun-kumar286\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/65023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/109"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=65023"}],"version-history":[{"count":11,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/65023\/revisions"}],"predecessor-version":[{"id":65045,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/65023\/revisions\/65045"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/62042"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=65023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=65023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=65023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}