Rewrite Isuues in custom taxanomy
-
Problem in hand :
I have custom categories in wordpress named “Product Categories” with custom post type “Products”.
i want to change urls from
somesite.com/product/airconditioner/voltas/productname
tosomesite.com/airconditioner/voltas/productname
Code to register post and categoriesclass aw_products_post_type { function __construct(){ $this->aw_register_post_type(); $this->aw_add_post_type_actions(); $this->aw_add_post_type_filters(); } 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 = $slug_first_part."/%product_category%/%product_brand%"; } // 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 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'taxonomies' => array('post_tag'), 'supports' => array('title','editor','author','thumbnail','excerpt', 'comments', 'tags') );
Value of tz_custom_products_slug in wp_option -> Product
Solutions tried in .htaccess
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteRule ^product/(.+)$ /$1 [L,R] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1.php -f RewriteRule ^(.+?)/?$ $1.php [L] </IfModule>
The above solution didn’t worked.
Solution 2 Tried and failed as follows:
changed this from above code $slug = $slug_first_part.”/%product_category%/%product_brand%”;
to this
$slug = “/%product_category%/%product_brand%”;
This caused 2nd custom taxanomy as page not found that is brands that shows urls like this :sitename.com/brands/acer/
If you need the whole custom taxanomy code for brand and product_category let me know.To check the original urls check it on : https://www.pricereview.in/product/digital-cameras/olympus/olympus-sz-17-digital-camera/
Similarly my custom taxanomy contains basename categories. i also want to remove it.
This is how urls are working. i want to convert this
https://www.pricereview.in/categories/mobile-price-in-india/
to
- The topic ‘Rewrite Isuues in custom taxanomy’ is closed to new replies.