{"_id":"54359c9e5e1b202000438229","__v":24,"is_link":false,"project":"5431c59ea55723080068e155","parentDoc":null,"version":{"_id":"5431c59ea55723080068e158","project":"5431c59ea55723080068e155","__v":8,"createdAt":"2014-10-05T22:26:38.927Z","releaseDate":"2014-10-05T22:26:38.927Z","categories":["5431c59ea55723080068e159","54325f53f2f806080098ad37","543264b1f2f806080098ad3e","543264c8f2f806080098ad3f","543264d3f2f806080098ad40","543264f42aca39080046d81e","5435bbf15e1b20200043834d","54e9cfb4f152c50d009b49ed"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"54e9cfb4f152c50d009b49ed","project":"5431c59ea55723080068e155","pages":["568507b4f72e9e0d00e09934"],"version":"5431c59ea55723080068e158","__v":1,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-02-22T12:46:44.278Z","from_sync":false,"order":1,"slug":"creation","title":"Tutorial"},"user":"542ea80e6b0eb6080066c9d5","updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-10-08T20:20:46.068Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","try":true,"basic_auth":false,"auth":"never","params":[],"url":""},"isReference":false,"order":2,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Make the Tea Theme Options working\"\n}\n[/block]\nAs we said before:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nuse crewstyle\\\\TeaThemeOptions\\\\TeaThemeOptions;\\n\\n//Include composer autoload\\nrequire_once __DIR__.'/vendor/autoload.php';\\n\\n//Instanciate a new TeaThemeOptions\\n$tea = new TeaThemeOptions();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Define what you want\"\n}\n[/block]\nSpecify your wanted components:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n//Build post type\\n$tea_configs = array(\\n  'slug' => 'project',\\n\\n  'labels' => array(\\n    'name' => __('Projects'),\\n    'singular_name' => __('Project'),\\n  ),\\n\\n  'capability_type' => 'post',\\n  'has_archive' => true,\\n  'hierarchical' => false,\\n  'menu_icon' => 'dashicons-portfolio',\\n  'menu_position' => 5,\\n  'public' => true,\\n  'query_var' => true,\\n  'show_ui' => true,\\n\\n  'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revision', 'comments'),\\n  'taxonomies' => array(),\\n);\\n//Build contents\\n$tea_contents = array(\\n  array(\\n    'type' => 'textarea',\\n    'id' => 'source',\\n    'title' => 'Video URL',\\n    'placeholder' => 'http://...',\\n    'description' => 'Enter here your Video URL.'\\n  )\\n);\\n\\n//Add post type to WP\\n$tea->addPostType($tea_configs, $tea_contents);\\n//Delete variables because we love our server!\\nunset($tea_configs, $tea_contents);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nIf you need to upgrade `post` or `page` post types, you can do it in the backend panel only:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n//Check if we are in the admin panel\\nif (is_admin()) {\\n  //Build post type\\n  $tea_configs = array(\\n    'title' => 'post',\\n    'slug' => 'post' //or 'page'\\n  );\\n\\n  //Build contents\\n  $tea_contents = array(\\n    array(\\n      'type' => 'select',\\n      'id' => 'select_box_id',\\n      'title' => 'A selectbox',\\n      'default' => 'great',\\n      'options' => array(\\n        'lovethat' => 'I love that!',\\n        'great' => 'GREAT',\\n        'toobad' => 'Too baaaaaaaaaaad!',\\n      )\\n    )\\n  );\\n\\n  //Add post type to WP\\n  $tea->addPostType($tea_configs, $tea_contents);\\n  //Delete variables because we love our server!\\n  unset($tea_configs, $tea_contents);\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Build the CPT\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n//Build post types\\n$tea->buildPostTypes();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"4. All in one\"\n}\n[/block]\nHere is a complete snapshot of what you have to do. Remember to make all these modifications in your `functions.php` theme file.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nuse crewstyle\\\\TeaThemeOptions\\\\TeaThemeOptions;\\n\\n//Include composer autoload\\nrequire_once __DIR__.'/vendor/autoload.php';\\n\\n//Instanciate a new TeaThemeOptions\\n$tea = new TeaThemeOptions();\\n\\n//Build post type\\n$tea_configs = array(\\n  'slug' => 'project',\\n\\n  'labels' => array(\\n    'name' => __('Projects'),\\n    'singular_name' => __('Project'),\\n  ),\\n\\n  'capability_type' => 'post',\\n  'has_archive' => true,\\n  'hierarchical' => false,\\n  'menu_icon' => 'dashicons-portfolio',\\n  'menu_position' => 5,\\n  'public' => true,\\n  'query_var' => true,\\n  'show_ui' => true,\\n\\n  'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revision', 'comments'),\\n  'taxonomies' => array(),\\n);\\n//Build contents\\n$tea_contents = array(\\n  array(\\n    'type' => 'textarea',\\n    'id' => 'source',\\n    'title' => 'Video URL',\\n    'placeholder' => 'http://...',\\n    'description' => 'Enter here your Video URL.'\\n  )\\n);\\n\\n//Add post type to WP\\n$tea->addPostType($tea_configs, $tea_contents);\\n//Delete variables because we love our server!\\nunset($tea_configs, $tea_contents);\\n\\n//Check if we are in the admin panel\\nif (is_admin()) {\\n  //Build post type\\n  $tea_configs = array(\\n    'title' => 'post',\\n    'slug' => 'post' //or 'page'\\n  );\\n\\n  //Build contents\\n  $tea_contents = array(\\n    array(\\n      'type' => 'select',\\n      'id' => 'select_box_id',\\n      'title' => 'A selectbox',\\n      'default' => 'great',\\n      'options' => array(\\n        'lovethat' => 'I love that!',\\n        'great' => 'GREAT',\\n        'toobad' => 'Too baaaaaaaaaaad!',\\n      )\\n    )\\n  );\\n\\n  //Add post type to WP\\n  $tea->addPostType($tea_configs, $tea_contents);\\n  //Delete variables because we love our server!\\n  unset($tea_configs, $tea_contents);\\n}\\n\\n//Build post types\\n$tea->buildPostTypes();\",\n      \"language\": \"php\",\n      \"name\": \"functions.php\"\n    }\n  ]\n}\n[/block]\nPay attention: do not hesitate to make conditions on what you need in your backend panel versus what you need in your frontend website.","excerpt":"With an other tiny example :)","slug":"create-a-custom-post-type","type":"basic","title":"Create a custom post type"}

Create a custom post type

With an other tiny example :)

[block:api-header] { "type": "basic", "title": "1. Make the Tea Theme Options working" } [/block] As we said before: [block:code] { "codes": [ { "code": "<?php\n\nuse crewstyle\\TeaThemeOptions\\TeaThemeOptions;\n\n//Include composer autoload\nrequire_once __DIR__.'/vendor/autoload.php';\n\n//Instanciate a new TeaThemeOptions\n$tea = new TeaThemeOptions();", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "2. Define what you want" } [/block] Specify your wanted components: [block:code] { "codes": [ { "code": "<?php\n\n//Build post type\n$tea_configs = array(\n 'slug' => 'project',\n\n 'labels' => array(\n 'name' => __('Projects'),\n 'singular_name' => __('Project'),\n ),\n\n 'capability_type' => 'post',\n 'has_archive' => true,\n 'hierarchical' => false,\n 'menu_icon' => 'dashicons-portfolio',\n 'menu_position' => 5,\n 'public' => true,\n 'query_var' => true,\n 'show_ui' => true,\n\n 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revision', 'comments'),\n 'taxonomies' => array(),\n);\n//Build contents\n$tea_contents = array(\n array(\n 'type' => 'textarea',\n 'id' => 'source',\n 'title' => 'Video URL',\n 'placeholder' => 'http://...',\n 'description' => 'Enter here your Video URL.'\n )\n);\n\n//Add post type to WP\n$tea->addPostType($tea_configs, $tea_contents);\n//Delete variables because we love our server!\nunset($tea_configs, $tea_contents);", "language": "php" } ] } [/block] If you need to upgrade `post` or `page` post types, you can do it in the backend panel only: [block:code] { "codes": [ { "code": "<?php\n\n//Check if we are in the admin panel\nif (is_admin()) {\n //Build post type\n $tea_configs = array(\n 'title' => 'post',\n 'slug' => 'post' //or 'page'\n );\n\n //Build contents\n $tea_contents = array(\n array(\n 'type' => 'select',\n 'id' => 'select_box_id',\n 'title' => 'A selectbox',\n 'default' => 'great',\n 'options' => array(\n 'lovethat' => 'I love that!',\n 'great' => 'GREAT',\n 'toobad' => 'Too baaaaaaaaaaad!',\n )\n )\n );\n\n //Add post type to WP\n $tea->addPostType($tea_configs, $tea_contents);\n //Delete variables because we love our server!\n unset($tea_configs, $tea_contents);\n}", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "3. Build the CPT" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n//Build post types\n$tea->buildPostTypes();", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "4. All in one" } [/block] Here is a complete snapshot of what you have to do. Remember to make all these modifications in your `functions.php` theme file. [block:code] { "codes": [ { "code": "<?php\n\nuse crewstyle\\TeaThemeOptions\\TeaThemeOptions;\n\n//Include composer autoload\nrequire_once __DIR__.'/vendor/autoload.php';\n\n//Instanciate a new TeaThemeOptions\n$tea = new TeaThemeOptions();\n\n//Build post type\n$tea_configs = array(\n 'slug' => 'project',\n\n 'labels' => array(\n 'name' => __('Projects'),\n 'singular_name' => __('Project'),\n ),\n\n 'capability_type' => 'post',\n 'has_archive' => true,\n 'hierarchical' => false,\n 'menu_icon' => 'dashicons-portfolio',\n 'menu_position' => 5,\n 'public' => true,\n 'query_var' => true,\n 'show_ui' => true,\n\n 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revision', 'comments'),\n 'taxonomies' => array(),\n);\n//Build contents\n$tea_contents = array(\n array(\n 'type' => 'textarea',\n 'id' => 'source',\n 'title' => 'Video URL',\n 'placeholder' => 'http://...',\n 'description' => 'Enter here your Video URL.'\n )\n);\n\n//Add post type to WP\n$tea->addPostType($tea_configs, $tea_contents);\n//Delete variables because we love our server!\nunset($tea_configs, $tea_contents);\n\n//Check if we are in the admin panel\nif (is_admin()) {\n //Build post type\n $tea_configs = array(\n 'title' => 'post',\n 'slug' => 'post' //or 'page'\n );\n\n //Build contents\n $tea_contents = array(\n array(\n 'type' => 'select',\n 'id' => 'select_box_id',\n 'title' => 'A selectbox',\n 'default' => 'great',\n 'options' => array(\n 'lovethat' => 'I love that!',\n 'great' => 'GREAT',\n 'toobad' => 'Too baaaaaaaaaaad!',\n )\n )\n );\n\n //Add post type to WP\n $tea->addPostType($tea_configs, $tea_contents);\n //Delete variables because we love our server!\n unset($tea_configs, $tea_contents);\n}\n\n//Build post types\n$tea->buildPostTypes();", "language": "php", "name": "functions.php" } ] } [/block] Pay attention: do not hesitate to make conditions on what you need in your backend panel versus what you need in your frontend website.