【问题标题】:Cannot rename the slug for a custom post type无法重命名自定义帖子类型的 slug
【发布时间】: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

【问题讨论】:

    标签: php wordpress custom-post-type slug


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 2021-10-17
      • 2014-11-10
      • 2017-01-31
      • 2021-08-21
      • 2018-11-23
      • 2016-01-18
      • 2017-09-19
      • 2018-09-15
      相关资源
      最近更新 更多