我在WordPress应用程序中创建了一个自定义帖子类型,我希望其URL通过连字符分隔。例如,自定义帖子的名称为Singh Across The World
,URL为singhacrosstheworld
,并且希望它为singh-across-the-world
。
我尝试使用singh-across-the-world
/ singh_across_the_world
而不是singhAcrossTheWorld
作为第一个参数,但这没有用。
以下是代码,请看一下:
register_post_type("singhAcrossTheWorld", [
"capability_type" => "post",
"description" => "Holds our Singh's specific data",
"public" => true,
"menu_position" => 6,
"has_archive" => true,
"show_admin_column" => true,
"supports" => [
"title",
"editor",
"thumbnail",
"excerpt",
"revisions",
"comments",
"custom-fields",
"page-attributes"
],
"taxonomies" => [
"post_tag"
],
"labels" => [
"name" => "Singh across the world",
"singular_name" => "Singh across the world",
"add_new" => "Add Singh",
"add_new_item" => "Add Singh",
"edit_item" => "Edit Singh",
"new_item" => "New Singh",
"all_items" => "All Singhs",
"view_item" => "View Singh",
"search_items" => "Search Singhs",
"not_found" => "No Singhs found",
"not_found_in_trash" => "No Singhs found in the Trash",
"parent_item_colon" => "",
"menu_name" => "S. A. T. W."
]
]);
答案 0 :(得分:1)
添加此参数rewrite' => array(
'slug' => 'singh-across-the-world'
)
register_post_type("singhAcrossTheWorld", [
"capability_type" => "post",
"description" => "Holds our Singh's specific data",
"public" => true,
"menu_position" => 6,
"has_archive" => true,
"show_admin_column" => true,
"supports" => [
"title",
"editor",
"thumbnail",
"excerpt",
"revisions",
"comments",
"custom-fields",
"page-attributes"
],
"taxonomies" => [
"post_tag"
],
"labels" => [
"name" => "Singh across the world",
"singular_name" => "Singh across the world",
"add_new" => "Add Singh",
"add_new_item" => "Add Singh",
"edit_item" => "Edit Singh",
"new_item" => "New Singh",
"all_items" => "All Singhs",
"view_item" => "View Singh",
"search_items" => "Search Singhs",
"not_found" => "No Singhs found",
"not_found_in_trash" => "No Singhs found in the Trash",
"parent_item_colon" => "",
"menu_name" => "S. A. T. W."
],
'rewrite' => array(
'slug' => 'singh-across-the-world'
)
]);