Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义帖子类型的自定义分类的重新布线规则_Php_Wordpress_Rewrite_Custom Post Type - Fatal编程技术网

Php 自定义帖子类型的自定义分类的重新布线规则

Php 自定义帖子类型的自定义分类的重新布线规则,php,wordpress,rewrite,custom-post-type,Php,Wordpress,Rewrite,Custom Post Type,所以我花了将近一周的时间试图解决这个问题, 我有一个自定义的post类型,名为Product,带有一个自定义的分类法,名为Category。 我想要的是,当我访问类似于acme.com/products/category/cctv的url时,能够列出类别中的所有产品,在这种情况下,我希望它显示类别cctv中的所有产品,但它将我重定向到404页面。我已经证实?product_category=cctv有效,这就是我如何得出问题在于重写规则的结论。 这是我的密码, 产品自定义帖子类型 $ar

所以我花了将近一周的时间试图解决这个问题, 我有一个自定义的post类型,名为
Product
,带有一个自定义的分类法,名为
Category
。 我想要的是,当我访问类似于
acme.com/products/category/cctv
的url时,能够列出类别中的所有产品,在这种情况下,我希望它显示类别
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
);

好了。请有人解释为什么这不起作用。

您采取了哪些调试步骤来确定问题的原因?是否记录了任何错误?通常情况下,您应该尝试将代码简化为一个包含任何错误或不正确输出详细信息的版本。我已经验证了
?product_category=cctv
是否有效,这就是我得出的结论,即问题在于重写规则。请将该信息编辑到您的问题中。我没有回答你的问题所需的专业知识,但这类信息对潜在的回答者来说可能是必不可少的。我可以假设你刷新了重写规则吗?@bobdye yep。。。我希望url是
acme.com/products/category/cctv
,你建议的只适用于
acme.com/category/cctv
,并且在你的
注册(你的分类
上,你已经将分类名称与自定义帖子名称交换了。
register_taxonomy( 'products', 'category', $args ); and Change
$rewrite = array(
'slug'                       => 'category',
'with_front'                 => true,
'hierarchical'               => true,
);