设置服务的自定义发布类型和服务类型的自定义分类法。将显示服务发布类型,但页面上没有添加服务类型分类的选项。这是我的代码:
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 );