I managed to get it fixed with the advice from tom. This is the solution I tried.
function product_perma_Rewrite() {
$prodCat = ['taxonomy' => 'product_cat'];
$categories = get_categories($prodCat);
$catSlug = [];
foreach($categories as $category) {
$catSlug[] = $category->slug;
}
add_rewrite_rule(
'^('.implode('|', $catSlug).')/([^/]+)/comment-page-([0-9]{1,})/?$',
'index.php?post_type=product&category=$matches[1]&product=$matches[2]&cpage=$matches[3]','top'
);
add_rewrite_rule(
'^('.implode('|', $catSlug).')/([^/]*)/?',
'index.php?post_type=product&category=$matches[1]&product=$matches[2]',
'top'
);
flush_rewrite_rules();
}
add_action('init', 'product_perma_Rewrite');
Related Posts:
- Get the current page URL (including pagination)
- Why is “/page/2/” not working?
- Get current URL (permalink) without /page/{pagenum}/
- Date based URLs for custom posts and pagination
- Adding anchor to paginate_links + Safari anchor bug
- 404 on category.php pagination
- Add ‘articles’ prefix before blog posts url without affecting pagination
- Clean install – Changing permalinks in twentyeleven give 404
- Custom permalink for search and pagination
- wp_logout_url redirects to incorrect page because of pagination
- How to Get Page 2 / Paginated RSS Feed with Custom Permalink Structure?
- Pagination Issue – /page/2 404
- next_posts_link URL does not include name of custom post type
- Why is page/2/ not working?
- How to handle paging/pagination with a custom permalink?
- Change permalink structure for pagination only
- Pagination using paginate_links
- Home page Pagination – Other pages do not redirect to home page template
- Pagination url for page template
- problem with pagination in custom permalinks
- WordPress /page/2 gives 404 when custom permalinks is set to %category%%postname%
- How to get a clean pagination link without variable
- Added .html to Woocommerce permalink but pagination don’t work!
- Pagination links for taxonomy archive page 404 error on every page except first
- WordPress Pagination Not Working After Transfer from Localhost
- Add Custom Pagination Permalink
- Search page Paginations not working
- Pagination is not working, how to trace it properly?
- How to change pagination base from slash to query form?
- Category pagination first link works, remaining don’t
- Getting the terms from “Beautiful Taxonomy Filters” Results ot Integrate into “Ajax Load More”
- Post archive pages bringing me to a 404 page
- What is the difference between get_post_permalink and get_permalink?
- WordPress matching URLs with trailing tildes
- Rewrite Rule for Multilingual Website, Like qTranslate?
- How to use relative links on my pages?
- How to filter to output of the get_permalink() function
- Change slug on post creation
- WordPress Permalink changes to question mark (?) in URL
- Is there a user-facing interface to edit an attachment’s permalink?
- Can WordPress realistically handle a site with 500 ‘pages’?
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- WordPress on a subdirectory of Laravel – WordPress pretty permalinks inner page shows laravel
- How to get url of a post from admin panel
- Custom Permalink: /year/month/post-goes-here/?
- Get post title with link
- WooCommerce permalinks [closed]
- CPT archive 404ing when using a custom taxonomy name as a variable
- Menu Link Redirect Based on Username or User ID
- Performance and styles not working fine after changing permalink structure
- Redirect short-form URL to long-form URL (post_id to post_id + post_name)
- Maintaining two permalink structures
- Does a parent page’s post_title have to appear in a child page permalink?
- Enable Minify in W3Total Cache using NGINX [closed]
- Can’t change permalink url after hitting ‘ok’ and ‘update’
- Rewrite user profile URL to be human friendly
- removing index.php IIS 7.5 webconfig
- How to make variables in URL look like the permalink structure?
- Why I can’t change the permalink of this page?
- Sub-category and category in permalink structure
- Permalinks Messed up
- Permalinks changed with WordPress 4.9
- Permalinks broken regularly
- 404 Page Not Found for Only One Post
- How to 301 all posts
- WordPress within specific sub-directories, implicitly not root
- Call to a member function add_rule() on a non-object
- Link to blog index from template
- How to change Post ID during import
- How can I add a page’s ID to its permalink using WP_Rewrite?
- Permalink change made author archive vanished
- Debugging permalink issue
- WordPress 404 in development area
- How to change the permalink option to post name on theme activation?
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- Changing post content on save, using updated fields
- Change blog segment of URL
- Custom Permalink
- Change in permalink structure made javascript cookie not work correctly
- why some permalinks adding characters/ruining links
- Making permalinks to /%postname%/ by default in installation
- Multiple taxonomies on same permalink rule [closed]
- How to bulk edit image url in featured image and product description?
- WordPress category base not in post permalink
- What’s actually happening when permalinks for custom post types suddenly stop working
- Redirect a Blogger Page URL to wordpress
- How to prevent redirect when using the term “page” in query string?
- Images in media library have suddenly disappeared
- Edit page slug after save, cause 404 by linked pages
- Post with Custom Permalinks
- Can’t select blog month within archive category
- Conditional permalink structure
- Auto setup “permalink” or request notice
- How to add .html to the end of the permalink
- IIS 7 Rewrite with parent categories
- Plugins, themes and other dashboard links including permalinks giving 404 error
- I am getting 500 error when enabling pretty permalinks
- Automatically added -2 in permalink after set number as permalink
- All WP pages direct to 404 or index.php
- Get Page URl when changing slug and permalink