set up a custom post type for service and a custom taxonomy for service type. The services post type is showing up but there is no option on the page to add the services-type taxonomy. Here is my code:
function create_posttypes() {
register_taxonomy(
'service-type', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'services', //post type name
array(
'hierarchical' => true,
'label' => 'Service Types', //Display name
'query_var' => true,
'rewrite' => array(
'slug' => 'service', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
//Services Post Type and Categories
$labels = array(
'name' => __( 'Services' ),
'singular_name' => __( 'Service' ),
'all_items' => __( 'All Services' ),
'view_item' => __( 'View Service' ),
'add_new_item' => __( 'Add New Service' ),
'edit_item' => __( 'Edit Service' ),
'update_item' => __( 'Update Service' ),
'search_items' => __( 'Search Services' ),
'not_found' => __( 'Not Found' ),
'not_found_in_trash' => __( 'Not Found in Trash' ),
);
$args = array(
'label' => 'Services',
'description' => 'Directory of Services',
'labels' => $labels,
'public' => true,
'query_var' => true,
'has_archive' => true,
'rewrite' => array('slug'=> 'services', 'with_front' => false),
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'taxonomies' => array( 'post_tag','service-type'),
'supports' => array('title','thumbnail', 'revisions', 'excerpt', 'editor')
);
register_post_type( 'services', $args );
}
add_action( 'init', 'create_posttypes', 0 );
set up a custom post type for service and a custom taxonomy for service type. The services post type is showing up but there is no option on the page to add the services-type taxonomy. Here is my code:
function create_posttypes() {
register_taxonomy(
'service-type', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'services', //post type name
array(
'hierarchical' => true,
'label' => 'Service Types', //Display name
'query_var' => true,
'rewrite' => array(
'slug' => 'service', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
//Services Post Type and Categories
$labels = array(
'name' => __( 'Services' ),
'singular_name' => __( 'Service' ),
'all_items' => __( 'All Services' ),
'view_item' => __( 'View Service' ),
'add_new_item' => __( 'Add New Service' ),
'edit_item' => __( 'Edit Service' ),
'update_item' => __( 'Update Service' ),
'search_items' => __( 'Search Services' ),
'not_found' => __( 'Not Found' ),
'not_found_in_trash' => __( 'Not Found in Trash' ),
);
$args = array(
'label' => 'Services',
'description' => 'Directory of Services',
'labels' => $labels,
'public' => true,
'query_var' => true,
'has_archive' => true,
'rewrite' => array('slug'=> 'services', 'with_front' => false),
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'taxonomies' => array( 'post_tag','service-type'),
'supports' => array('title','thumbnail', 'revisions', 'excerpt', 'editor')
);
register_post_type( 'services', $args );
}
add_action( 'init', 'create_posttypes', 0 );
Share
Improve this question
asked May 29, 2019 at 12:37
jppower175jppower175
2832 silver badges13 bronze badges
2
- This works fine for me. You might have something else that's causing a conflict. – MikeNGarrett Commented May 29, 2019 at 15:41
- Forgive what might sound like a silly question, but did you try going up to "Screen Options" and ensuring that your new taxonomy module is checked? When you expand Screen Options you should see a checkbox for 'Service Types' that you should check if it isn't. – Trisha Commented Jun 4, 2019 at 18:46
1 Answer
Reset to default 6With the new WordPress admin area "show_in_rest" must be set to true for custom taxonomies to show up in page editor.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745419154a4626888.html
评论列表(0条)