Problems with $wp_rewrite
-
Hello guys!
I have a problem, which I need some help to solve.
Okay – here goes the explanation:– I have a customer, who has a shop plugin and a custom post type called “dictionary”. The problem is, when you go to an shop-item, it shows up fine – the link looks like this:
“www.mysite.com/shoes/sneakers/vans/vans-s-3”
Thats okay.. But there’s a problem here… I can change “shoes” and “sneakers” to whatever I want, and it will STILL show me the correct product(!)
While products are working (somewhat working) – dictionary is more problematic.
When I add a word in the dictionary, it shows the url:“www.mysite.com/ord/hello”
When I visit this URL – nothing comes up – I get an 404-page.
BUT! If i go to the backend, and update the post, then I can visit the exact same URL, and it’s working!I’ve narrowed it down to this function:
add_action( 'generate_rewrite_rules', 'register_product_rewrite_rules' ); function register_product_rewrite_rules( $wp_rewrite ) { $new_rules = array( '([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/page/(\d{1,})/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 5 ) . '&paged=' . $wp_rewrite->preg_index( 6 ), '([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 5 ), '([^/]+)/([^/]+)/([^/]+)/([^/]+)/page/(\d{1,})/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 4 ) . '&paged=' . $wp_rewrite->preg_index( 5 ), '([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 4 ), '([^/]+)/([^/]+)/([^/]+)/page/(\d{1,})/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 3 ) . '&paged=' . $wp_rewrite->preg_index( 4 ), '([^/]+)/([^/]+)/([^/]+)/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 3 ), '([^/]+)/([^/]+)/page/(\d{1,})/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 2 ) . '&paged=' . $wp_rewrite->preg_index( 3 ), '([^/]+)/([^/]+)/?$' => 'index.php?name=' . $wp_rewrite->preg_index( 2 ), '([^/]+)/([^/]+)/([^/]+)/' => 'index.php?name=' . $wp_rewrite->preg_index( 2 ) ); $wp_rewrite->rules = $new_rules+$wp_rewrite->rules; }
To summarize in short:
– Products are working – but I can change some of the URL as I want
– Dictionary is NOT working, unless I update the postIf I disable/remove this function, dictionary is working fine – but then products are not working at all… Please help me – I’m so lost right now…
Best regards
Aris Kuckovic
- The topic ‘Problems with $wp_rewrite’ is closed to new replies.