简体   繁体   English

更改自定义帖子类型的标签会导致单个帖子类型和页面产生404

[英]Changing the slug for custom post type resulted in 404 for single post type and pages

My website have custom post type : products and tied to custom taxonomy : categories. 我的网站具有自定义帖子类型:产品,并且与自定义分类法相关:类别。

Currently my URLs for particular product is like this: 目前,我针对特定产品的网址是这样的:

example.com/product/laptop/acer/acerproductname

As I wanted to remove the slug and URLs should look like this 由于我想删除该子弹,因此网址应如下所示

example.com/laptop/acer/acerproductname

so to remove this, I changed the slug while registering custom post type. 因此,为消除此问题,我在注册自定义帖子类型时更改了子弹。

from

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

to

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

Now the post register function look like this 现在,后注册功能如下所示

  public function aw_register_post_type(){ // Labels $labels = array( 'name' => __('Products','framework'), 'singular_name' => __('Product','framework'), 'add_new' => __('Add new','framework'), 'add_new_item' => __('Add new product','framework'), 'edit_item' => __('Edit','framework'), 'new_item' => __('New product','framework'), 'view_item' => __('View product','framework'), 'search_items' => __('Search product','framework'), 'not_found' => __('No product found','framework'), 'not_found_in_trash' => __('No product found in trash','framework'), 'parent_item_colon' => '', 'menu_name' => __('Products','framework') ); $short_url = (get_option('tz_products_short_url') != '') ? get_option('tz_products_short_url') : 0; $slug_first_part = ((get_option('tz_custom_products_slug') != '') ? get_option('tz_custom_products_slug') : 'product'); if($short_url == 1) { $slug = $slug_first_part; } else { $slug = "/%product_category%/%product_brand%"; } $rewrite = array( 'slug' => $slug, //'with_front' => false ); // Arguments $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'menu_icon' => get_stylesheet_directory_uri().'/img/admin/admin-products.png', 'rewrite' => true, 'capability_type' => 'post', //'rewrite' => array("slug" => $slug), // Permalinks format 'rewrite' => $rewrite, 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'taxonomies' => array('post_tag'), 'supports' => array('title','editor','author','thumbnail','excerpt', 'comments', 'tags') ); 

Now the URLs for custom post type is exactly what I wanted that is 现在,自定义帖子类型的网址正是我想要的

 example.com/laptop/acer/acerproductname

Main Problem 主要问题

After changing the slug my blogs and other pages now showing 404 error. 更改后,我的博客和其他页面现在显示404错误。 What can be the possible reason and what can be the possible solution for this. 可能是什么原因,什么是可能的解决方案。

Try adding this into your functions.php 尝试将其添加到您的functions.php中

flush_rewrite_rules();

Comment it out once you've refreshed the page. 刷新页面后,将其注释掉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM