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錯誤後。可能的原因是什麼以及可能的解決方案是什麼。
如果您取消註釋'with_front'=> false,它會起作用嗎?變更後你會做flush_rewrite_rules()嗎? –
取消註釋並沒有什麼區別。不,我沒有。 –
刷新它仍然沒有區別 –