再花点时间四处搜索,我找到了答案。。。给你,以防对其他人有帮助。
在创建自定义帖子类型的函数中,我添加了以下内容:
$rewrite = array(
\'slug\' => \'results/testimonials\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
因此,完整的自定义帖子类型代码现在是:
/*
* Creating a function to create our CPT
*/
static function testimonial_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
\'name\' => _x( \'Testimonials\', \'Post Type General Name\'),
\'singular_name\' => _x( \'Testimonial\', \'Post Type Singular Name\'),
\'menu_name\' => __( \'Testimonials\'),
\'parent_item_colon\' => __( \'Parent Testimonial\'),
\'all_items\' => __( \'All Testimonials\'),
\'view_item\' => __( \'View Testimonial\'),
\'add_new_item\' => __( \'Add New Testimonial\'),
\'add_new\' => __( \'Add New\'),
\'edit_item\' => __( \'Edit Testimonial\'),
\'update_item\' => __( \'Update Testimonial\'),
\'search_items\' => __( \'Search Testimonial\'),
\'not_found\' => __( \'Not Found\'),
\'not_found_in_trash\' => __( \'Not found in Trash\'),
);
$rewrite = array(
\'slug\' => \'results/testimonials\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
// Set other options for Custom Post Type
$args = array(
\'label\' => __( \'testimonials\'),
\'description\' => __( \'Client testimonials\'),
\'labels\' => $labels,
// Features this CPT supports in Post Editor
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'revisions\', \'custom-fields\',\'page-attributes\' ),
// You can associate this CPT with a taxonomy or custom taxonomy.
\'taxonomies\' => array( \'feature_on\',\'service\',\'industry\' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'post\',
\'menu_icon\' => "dashicons-thumbs-up",
\'rewrite\' => $rewrite,
"rest_base" => "Testimonial",
"rest_controller_class" => "WP_REST_Posts_Controller",
\'show_in_rest\' => true,
"query_var" => true,
);
// Registering your Custom Post Type
register_post_type( \'testimonials\', $args );
}
我希望这能帮助别人!