自定义帖子类型的自定义分类的重新连接规则

时间:2015-02-16 11:54:48

标签: php wordpress rewrite custom-post-type

所以我花了将近一周时间试图解决这个问题, 我有一个名为Product的自定义帖子类型,其中包含一个名为Category的自定义分类法。 我想要的是能够列出类似于acme.com/products/category/cctv的网址的所有类别的产品,在这种情况下我希望它显示类别cctv内的所有产品,但它重定向我到404页面。我已经验证了?product_category = cctv有效,这就是我得出的问题,即问题在于重写规则。
这是我的代码,

产品定制邮政类型

    $args = array(
            'labels'=>array(
                    'name' => 'Products',
                    'singular_name' => 'Product',
                    'add_new_item' => 'Add New Product',
                    'edit_item' => 'Edit Item',
                    'new_item'  => 'Add New Product',
                    'view_item' => 'View Product',
                    'search_items' => 'Search Products',
                    'not_found'    =>'No Products found',
                    'not_found_in_trash' => 'No Products found in trash'
            ),
            'taxonomies'   => array( 'product_category'),
            'query_var' => 'products',
            'rewrite' => array('slug' => 'products', 'with_front' => true, 'pages' => true, 'feeds' => true,),
            'has_archive' => true,
            'public'  => true,
            'menu_position' => 5,
            'menu_icon' => get_stylesheet_directory_uri() . '/library/images/products.png',
            'supports' => array(
                    'title',
                    'thumbnail',
                    'editor'
                ),
        );
register_post_type('tg_product',$args);



类别自定义分类

$labels = array(
    'name'                       => _x( 'Categories', 'Taxonomy General Name', 'alle360' ),
    'singular_name'              => _x( 'Category', 'Taxonomy Singular Name', 'alle360' ),
    'menu_name'                  => __( 'Categories', 'alle360' ),
    'all_items'                  => __( 'All Categories', 'alle360' ),
    'parent_item'                => __( 'Parent Category', 'alle360' ),
    'parent_item_colon'          => __( 'Parent Category:', 'alle360' ),
    'new_item_name'              => __( 'New Category Name', 'alle360' ),
    'add_new_item'               => __( 'Add New Category', 'alle360' ),
    'edit_item'                  => __( 'Edit Category', 'alle360' ),
    'update_item'                => __( 'Update Category', 'alle360' ),
    'separate_items_with_commas' => __( 'Separate categories with commas', 'alle360' ),
    'search_items'               => __( 'Search Categories', 'alle360' ),
    'add_or_remove_items'        => __( 'Add or remove categories', 'alle360' ),
    'choose_from_most_used'      => __( 'Choose from the most used categories', 'alle360' ),
    'not_found'                  => __( 'Not Found', 'alle360' ),
);
$rewrite = array(
    'slug'                       => 'products/category',
    'with_front'                 => true,
    'hierarchical'               => true,
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'query_var'                  => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
    'rewrite'                    => $rewrite
);

所以你有它。请有人说明为什么这不起作用。

1 个答案:

答案 0 :(得分:0)

register_taxonomy( 'products', 'category', $args ); and Change
$rewrite = array(
'slug'                       => 'category',
'with_front'                 => true,
'hierarchical'               => true,
);