如何为Wordpress自定义文章类型设置自定义分类URL


How do I set a custom taxonomy URL for Wordpress custom post types?

我在插件中使用以下内容来创建自定义帖子类型:

function post_type_listing() {
    $labels = array(
        'name' => _x('Listing', 'post type general name', 'themesdojo'),
        'singular_name' => _x('Listing', 'post type singular name', 'themesdojo'),
        'add_new' => _x('Add New Listing', 'book', 'themesdojo'),
        'add_new_item' => __('Add New Listing', 'themesdojo'),
        'edit_item' => __('Edit Listing', 'themesdojo'),
        'new_item' => __('New Listing', 'themesdojo'),
        'view_item' => __('View Listing', 'themesdojo'),
        'search_items' => __('Search Listing', 'themesdojo'),
        'not_found' =>  __('No Listing found', 'themesdojo'),
        'not_found_in_trash' => __('No Listing found in Trash', 'themesdojo'), 
        'parent_item_colon' => ''
    );      
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'query_var' => true,
        //'rewrite' => true,
        'rewrite'         => array(
                'slug'          => 'view',
                'with_front'    => true
            ),
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail','author', 'comments', 'amenities'),
        'menu_icon' => 'dashicons-menu'
    );      
    register_post_type( 'item', $args );    
} 
add_action('init', 'post_type_listing');

注意分类法的自定义重写:

'rewrite'         => array(
                'slug'          => 'view',
                'with_front'    => true
            ),

出于某种原因,这些帖子类型仍然显示http://example.com/item/%post_name%/.

我不知所措。我已经保存了永久链接并清除了缓存。没有骰子。

很可能是因为一个插件改变了url,我知道添加这个插件会做到这一点。我建议你看看你安装的wordpress插件。