http://www.phparch.com \ December 2018 \ 7
Custom Post Types in WordPress
You can also disable Gutenberg for a specific custom post
type by passing a callback function to the filter:
function wiverb_disable_gutenberg($is_enabled, $post_type) {
if ($post_type === 'wiverb_bike') {
return false;
}
return $is_enabled;
}
add_filter('gutenberg_can_edit_post_type',
'wiverb_disable_gutenberg', 10 , 2 );
Read more about disabling Gutenberg editor from Digging
into WordPress^8
What About Custom Fields?
Adding custom fields is a powerful way to add functionality
and structure to your custom post type data. If you are using
the Advanced Custom Fields (ACF) plugin, you can specify
that your custom field groups will appear on your custom
post type. You can then use data entered in these fields for
custom post type queries and templating.
8 Digging into WordPress: https://phpa.me/digwp-disable-gutenberg
Listing 5
- <?php
- /*
- Plugin Name: WI Verbs Nested Post Types
- Plugin URI: https://wisconsinverbs.com
- Description: Display Custom Post Types in a nested menu
- Version: 1.
- Author: Andrea Roenning
- Author URI: https://andrearoenning.com
- License: GPL
- License URI: https://www.gnu.org/licenses/gpl-2.0.html
- Text Domain: wiverb
- */
- if(!function_exists('wiverb_post_types')) {
- /**
- Adds custom post types
- */
- function wiverb_post_types() {
- /*
- Hiking Trail listing
- */
- register_post_type( 'wiverb_hike',
- array(
- 'labels' => array(
- 'name' => __( 'Hiking Trails' ),
- 'singular_name' => __( 'Hiking Trail' ),
- 'add_new_item' => __('Add New Trail'),
- 'edit_item' => __('Edit Trail'),
- 'new_item' => __('New trail'),
- 'view_item' => __('View trail'),
- 'search_items' => __('Search trails'),
- 'not_found' => __('No trails were found'),
- 'not_found_in_trash' => ('No trails found in trash')
- ),
- 'public' => true,
- 'show_in_menu' => false,
- 'exclude_from_search' => true,
- 'supports' => array(
- 'title', 'editor', 'thumbnail',
- 'revisions', 'page-attributes'),
- 'rewrite' => array( 'slug' => 'trails/hiking' ),
- 'has_archive' => 'trails/hiking'
- )
- );
- /*
- Biking Trail listing
- */
- register_post_type( 'wiverb_bike',
- array(
- 'labels' => array(
- 'name' => __( 'Biking Trails' ),
- 'singular_name' => ( 'Biking Trail' ),
53. 'add_new_item' => ('Add New Trail'),
54. 'edit_item' => ('Edit Trail'),
55. 'new_item' => __('New trail'),
56. 'view_item' => ('View trail'),
57. 'search_items' => __('Search trails'),
58. 'not_found' => __('No trails were found'),
59. 'not_found_in_trash' => ('No trails found in trash')
60. ),
61. 'public' => true,
62. 'show_in_menu' => false,
63. 'exclude_from_search' => true,
64. 'supports' => array(
65. 'title', 'editor', 'thumbnail',
66. 'revisions', 'page-attributes'),
67. 'rewrite' => array( 'slug' => 'trails/biking' ),
68. 'has_archive' => 'trails/biking'
69. )
70. );
71. }
72. add_action( 'init', 'wiverb_post_types' );
73. }
74. /
75. Admin Controls
76. */
77. if (!function_exists('wiverbs_trails_menu')) {
78. /
79. Adds admin nav & subnav
80. /
81. function wiverbs_trails_menu() {
82. add_menu_page(
83. 'Trails', 'Trails', 'edit_posts',
84. 'wiverbs_trails', 'wiverbs_trails_page',
85. 'dashicons-location-alt', 5
86. );
87.
88. add_submenu_page(
89. 'wiverbs_trails', 'Hiking Trails', 'Hiking Trails',
90. 'edit_posts', 'edit.php?post_type=wiverb_hike'
91. );
92.
93. add_submenu_page(
94. 'wiverbs_trails', 'Biking Trails', 'Biking Trails',
95. 'edit_posts', 'edit.php?post_type=wiverb_bike'
96. );
97. }
98. add_action( 'admin_menu', 'wiverbs_trails_menu' );
99. }
100.
101. if (!function_exists('wiverbs_trails_page')) {
102. /
View Code ARchive for Full Listing