无法重命名自定义帖子类型的 slug

Posted

技术标签:

【中文标题】无法重命名自定义帖子类型的 slug【英文标题】:Cannot rename the slug for a custom post type 【发布时间】:2013-09-10 15:38:21 【问题描述】:

我终生无法更改自定义帖子类型的 slug。我已经尝试刷新重写并重新保存我的永久链接。但它仍然显示旧的蛞蝓。

我的函数.php

register_post_type( 'roofers-peakdistrict',
    array(
        'labels' => array(
            'name' => __( 'Peak District' ),
            'singular_name' => __( 'Roofers Peak District' ),
            'add_new' => 'Add New Peak District Page',
            'add_new_item' => 'Add New Peak District Page',
            'edit' => 'Edit Peak District Page',
            'edit_item' => 'Edit Peak District Page',
            'new_item' => 'New Peak District Page',
            'view' => 'View Peak District Page',
            'view_item' => 'View Peak District Page',
            'search_items' => 'Search Peak District Pages',
            'not_found' => 'No Peak District Pages found',
            'has_archive' => true,
            'slug' => 'roofers-peak-district'
            'hierarchical' => true,
            'not_found_in_trash' => 'No Peak District Pages found in Trash',
            'parent' => 'Parent Peak District Page', ),
            'public' => true,
            'supports' => array(
                'title',
                'editor',
                'thumbnail'
                ),
            'taxonomies' => array('category'),
            )
        );

我的帖子像http://mysite.com/roofers-peakdistrict/mypost一样出来

我需要将其更改为http://mysite.com/roofers-peak-district/mypost

【问题讨论】:

【参考方案1】:

您使用了错误的数组 改用这个

register_post_type( 'roofers-peakdistrict',
    array(
        'labels' => array(
            'name' => __( 'Peak District' ),
            'singular_name' => __( 'Roofers Peak District' ),
            'add_new' => 'Add New Peak District Page',
            'add_new_item' => 'Add New Peak District Page',
            'edit' => 'Edit Peak District Page',
            'edit_item' => 'Edit Peak District Page',
            'new_item' => 'New Peak District Page',
            'view' => 'View Peak District Page',
            'view_item' => 'View Peak District Page',
            'search_items' => 'Search Peak District Pages',
            'not_found' => 'No Peak District Pages found', 
           ),
            'has_archive' => true,
            'rewrite' => array(
                  'slug'=>'roofers-peak-district'
             ),
            'hierarchical' => true,
            'not_found_in_trash' => 'No Peak District Pages found in Trash',
            'parent' => 'Parent Peak District Page',
          'public' => true,
          'supports' => array(
                 'title',
                 'editor',
                 'thumbnail'
           ),
           'taxonomies' => array('category'),
    )

);

更多细节和例子见 http://codex.wordpress.org/Function_Reference/register_post_type

【讨论】:

以上是关于无法重命名自定义帖子类型的 slug的主要内容,如果未能解决你的问题,请参考以下文章

文件路径乱码,无法打开、重命名、移动、删除、粉碎

文件夹为啥无法重命名?

php 在自定义类型中重命名标题占位符

powershell 重命名自定义对象并为新类型添加默认输出

WP-重命名自定义post类型和分类

apt无法重命名文件