WordPress 在自定义 post url 中添加连字符

WordPress adding hyphen in custom post url

我在我的 WordPress 应用程序中创建了一个自定义 post 类型,我希望它的 URL 通过连字符分隔。例如,自定义 post 的名称是 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."
    ]
]);

添加这个参数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'
    )
]);