deg Posted December 2, 2012 Share Posted December 2, 2012 In the below function I am trying to understand the $new_rules array. I understand it is matching a pattern an then rewriting that pattern to a friendly url. But I just don't understand the logic of what portion is capturing the pattern and what portion is telling it to rewrite in another format and what that format is. Could someone help me understand each section of the $new_array in basic terms so I can understand the logic of the matching and rewrite? I am trying to learn this but just can seem to get it. In this example cardealers is my custom post type, and brands and state are a taxonomy. Thank you! function eg_add_rewrite_rules() { global $wp_rewrite;[/font][/color] $new_rules = array( 'cardealers/(brands|state)/(.+?)/(brands|state)/(.+?)/?$' => 'index.php?post_type=cardealers&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) . '&' . $wp_rewrite->preg_index(3) . '=' . $wp_rewrite->preg_index(4), 'cardealers/(brands|state)/(.+)/?$' => 'index.php?post_type=cardealers&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' ); Quote Link to comment https://forums.phpfreaks.com/topic/271472-help-with-url-rewrite-wordpress/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.