wp_rewrite help
-
I’m not too familiar with wp_rewrite and need some help creating a simple rewrite. I’ve looked at the codex and it’s very limited on rewrite help for doing something simple.
I want to take the url:
https://mysite.com/tutorial/chp/1and rewrite it to:
https://mysite.com/tutorial/?chp=1
The catch is that I want the url all the way up to /chp in tact so that no matter what comes before /chp/ it’s used in the new url and the vars are added in.I have my permalinks set to the following:
/%category%/%postname%/I’m trying the current rewrite:
// URL rewrite // flush rules add_filter('init','wpngfb_flush'); function wpngfb_flush() { global $wp_rewrite; $wp_rewrite->flush_rules(); } // Add a new rule add_filter('rewrite_rules_array','wpngfb_rules'); function wpngfb_rules($rules) { $newrules = array(); $newrules['^(.*)/chp/([0-9]+)$'] = 'index.php?pagename=$matches[1]&chp=$matches[2]'; return $newrules + $rules; } // Add the chp var so that WP recognizes it add_filter('query_vars','wpngfb_var_insert'); function wpngfb_var_insert($vars) { array_push($vars, 'chp'); return $vars; }
This works some what, but it’s dropping the /chp/1 from the url completely and ignoring the var include
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘wp_rewrite help’ is closed to new replies.