2016-07-12 31 views
0

我的网站有自定义帖子类型:产品并绑定到自定义分类:类别。更改自定义帖子类型的slu resulted导致404单个帖子类型和页面

目前我对特定产品的URL是这样的:

example.com/product/laptop/acer/acerproductname 

因为我想删除蛞蝓和URL看起来应该是这样

example.com/laptop/acer/acerproductname 

所以要去除这一点,我改变了蛞蝓同时注册自定义帖子类型。

$slug = product."/%product_category%/%product_brand%"; 

$slug = "/%product_category%/%product_brand%"; 

现在补办登记功能看起来像这样

public function aw_register_post_type(){   
 
     // Labels 
 
\t $labels = array(
 
\t \t 'name' => __('Products','framework'), 
 
\t \t 'singular_name' => __('Product','framework'), 
 
\t \t 'add_new' => __('Add new','framework'), 
 
\t \t 'add_new_item' => __('Add new product','framework'), 
 
\t \t 'edit_item' => __('Edit','framework'), 
 
\t \t 'new_item' => __('New product','framework'), 
 
\t \t 'view_item' => __('View product','framework'), 
 
\t \t 'search_items' => __('Search product','framework'), 
 
\t \t 'not_found' => __('No product found','framework'), 
 
\t \t 'not_found_in_trash' => __('No product found in trash','framework'), 
 
\t \t 'parent_item_colon' => '', 
 
\t \t 'menu_name' => __('Products','framework') 
 
\t); 
 
\t 
 
\t $short_url = (get_option('tz_products_short_url') != '') ? get_option('tz_products_short_url') : 0; 
 
\t $slug_first_part = ((get_option('tz_custom_products_slug') != '') ? get_option('tz_custom_products_slug') : 'product'); 
 
\t if($short_url == 1) { 
 
\t \t $slug = $slug_first_part; 
 
\t \t 
 
\t } else { 
 
\t \t $slug = "/%product_category%/%product_brand%"; 
 

 
\t } 
 
\t $rewrite = array( 
 
    \t  \t 'slug'   => $slug, 
 
\t \t //'with_front' => false 
 
); 
 
\t 
 
\t // Arguments 
 
\t $args = array(
 
\t \t 'labels' => $labels, 
 
\t \t 'public' => true, 
 
\t \t 'publicly_queryable' => true, 
 
\t \t 'show_ui' => true, 
 
\t \t 'show_in_menu' => true, 
 
\t \t 'query_var' => true, 
 
\t \t 'menu_icon' => get_stylesheet_directory_uri().'/img/admin/admin-products.png', 
 
\t \t 'rewrite' => true, 
 
\t \t 'capability_type' => 'post', 
 
\t \t //'rewrite' => array("slug" => $slug), // Permalinks format 
 
\t \t 'rewrite' => $rewrite, 
 
\t \t 'has_archive' => true, 
 
\t \t 'hierarchical' => false, 
 
\t \t 'menu_position' => null, 
 
\t \t 'taxonomies' => array('post_tag'), 
 
\t \t 'supports' => array('title','editor','author','thumbnail','excerpt', 'comments', 'tags') 
 
\t);

现在对于自定义后类型的网址,这正是我想要的是

example.com/laptop/acer/acerproductname 

主要问题

改变嵌塞我的博客和其他网页现在显示404错误后。可能的原因是什么以及可能的解决方案是什么。

+0

如果您取消注释'with_front'=> false,它会起作用吗?变更后你会做flush_rewrite_rules()吗? –

+0

取消注释并没有什么区别。不,我没有。 –

+0

刷新它仍然没有区别 –

回答

0

尝试添加该到你的functions.php

flush_rewrite_rules(); 

评论它一旦你刷新页面。

+0

已经试过了。没用。正如其他一些开发者所讨论的。他说需要在functions.php中添加另一个重写规则行 –

相关问题