{"id":5191,"date":"2017-08-05T13:35:15","date_gmt":"2017-08-05T17:35:15","guid":{"rendered":"https:\/\/themespress.ca\/?p=5191"},"modified":"2022-10-01T15:06:28","modified_gmt":"2022-10-01T19:06:28","slug":"creating-a-custom-post-type","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/creating-a-custom-post-type\/","title":{"rendered":"Creating a Custom Post Type"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Using a Custom Post Type is a great way to separate your custom content from your post given that WordPress posts are for blogging and non necessarily custom content.<\/p>\n<p>So for example, let&#8217;s say you want to create a new section on your website, different from the blog, titled Tutorials. In order to display them accordingly, you&#8217;ll need to create a custom Post Type.<\/p>\n<p>Here&#8217;s how you can create your own Custom Post Type:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-7207901\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7207901\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/ Register Custom Post Type\nfunction theme_custom_post_type() {\n \n\t$labels = array(\n\t\t&#039;name&#039;                  =&gt; _x( &#039;Post Types&#039;, &#039;Post Type General Name&#039;, &#039;text_domain&#039; ),\n\t\t&#039;singular_name&#039;         =&gt; _x( &#039;Post Type&#039;, &#039;Post Type Singular Name&#039;, &#039;text_domain&#039; ),\n\t\t&#039;menu_name&#039;             =&gt; __( &#039;Post Types&#039;, &#039;text_domain&#039; ),\n\t\t&#039;name_admin_bar&#039;        =&gt; __( &#039;Post Type&#039;, &#039;text_domain&#039; ),\n\t\t&#039;archives&#039;              =&gt; __( &#039;Item Archives&#039;, &#039;text_domain&#039; ),\n\t\t&#039;attributes&#039;            =&gt; __( &#039;Item Attributes&#039;, &#039;text_domain&#039; ),\n\t\t&#039;parent_item_colon&#039;     =&gt; __( &#039;Parent Item:&#039;, &#039;text_domain&#039; ),\n\t\t&#039;all_items&#039;             =&gt; __( &#039;All Items&#039;, &#039;text_domain&#039; ),\n\t\t&#039;add_new_item&#039;          =&gt; __( &#039;Add New Item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;add_new&#039;               =&gt; __( &#039;Add New&#039;, &#039;text_domain&#039; ),\n\t\t&#039;new_item&#039;              =&gt; __( &#039;New Item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;edit_item&#039;             =&gt; __( &#039;Edit Item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;update_item&#039;           =&gt; __( &#039;Update Item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;view_item&#039;             =&gt; __( &#039;View Item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;view_items&#039;            =&gt; __( &#039;View Items&#039;, &#039;text_domain&#039; ),\n\t\t&#039;search_items&#039;          =&gt; __( &#039;Search Item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;not_found&#039;             =&gt; __( &#039;Not found&#039;, &#039;text_domain&#039; ),\n\t\t&#039;not_found_in_trash&#039;    =&gt; __( &#039;Not found in Trash&#039;, &#039;text_domain&#039; ),\n\t\t&#039;featured_image&#039;        =&gt; __( &#039;Featured Image&#039;, &#039;text_domain&#039; ),\n\t\t&#039;set_featured_image&#039;    =&gt; __( &#039;Set featured image&#039;, &#039;text_domain&#039; ),\n\t\t&#039;remove_featured_image&#039; =&gt; __( &#039;Remove featured image&#039;, &#039;text_domain&#039; ),\n\t\t&#039;use_featured_image&#039;    =&gt; __( &#039;Use as featured image&#039;, &#039;text_domain&#039; ),\n\t\t&#039;insert_into_item&#039;      =&gt; __( &#039;Insert into item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;uploaded_to_this_item&#039; =&gt; __( &#039;Uploaded to this item&#039;, &#039;text_domain&#039; ),\n\t\t&#039;items_list&#039;            =&gt; __( &#039;Items list&#039;, &#039;text_domain&#039; ),\n\t\t&#039;items_list_navigation&#039; =&gt; __( &#039;Items list navigation&#039;, &#039;text_domain&#039; ),\n\t\t&#039;filter_items_list&#039;     =&gt; __( &#039;Filter items list&#039;, &#039;text_domain&#039; ),\n\t);\n\t$args = array(\n\t\t&#039;label&#039;                 =&gt; __( &#039;Post Type&#039;, &#039;text_domain&#039; ),\n\t\t&#039;description&#039;           =&gt; __( &#039;Post Type Description&#039;, &#039;text_domain&#039; ),\n\t\t&#039;labels&#039;                =&gt; $labels,\n\t\t&#039;supports&#039;              =&gt; array( &#039;title&#039;, &#039;editor&#039;, &#039;excerpt&#039;, &#039;thumbnail&#039;, &#039;post-formats&#039;, ),\n\t\t&#039;taxonomies&#039;            =&gt; array( &#039;category&#039;, &#039;post_tag&#039; ),\n\t\t&#039;hierarchical&#039;          =&gt; false,\n\t\t&#039;public&#039;                =&gt; true,\n\t\t&#039;show_ui&#039;               =&gt; true,\n\t\t&#039;show_in_menu&#039;          =&gt; true,\n\t\t&#039;menu_position&#039;         =&gt; 5,\n\t\t&#039;show_in_admin_bar&#039;     =&gt; true,\n\t\t&#039;show_in_nav_menus&#039;     =&gt; true,\n\t\t&#039;can_export&#039;            =&gt; true,\n\t\t&#039;has_archive&#039;           =&gt; true,\t\t\n\t\t&#039;exclude_from_search&#039;   =&gt; false,\n\t\t&#039;publicly_queryable&#039;    =&gt; true,\n\t\t&#039;capability_type&#039;       =&gt; &#039;page&#039;,\n\t);\n\tregister_post_type( &#039;POSTTYPENAME&#039;, $args );\n \n}\nadd_action( &#039;init&#039;, &#039;theme_custom_post_type&#039;, 0 );<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"Using a Custom Post Type is a great way to separate your custom content from your post given that WordPress posts are for blogging and non necessarily custom content. So<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/creating-a-custom-post-type\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":5194,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[318],"class_list":["post-5191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-functions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=5191"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5191\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/5194"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=5191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=5191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=5191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}