Need Help With add_rewrite_rule Regex
-
add_action( 'init', 'add_position_rules' ); function add_position_rules() { add_rewrite_rule( "position/([0-9]{4}$)", "articles/wp-content/themes/adapt-child/position.php?position=$matches[1]", "top"); }
I’m so bad at regex…
Could someone please help me with this.
I want https://website/position/1234
to redirect to https://website/articles/wp-content/themes/adapt-child/position.php?position=1234Basically, all I’m trying to do is pull the number out of the URL and pass it in the query string.
When I tested this with straight PHP, it works fine:
$string = "/position/1234"; $pattern = '([0-9]{4}$)'; preg_match($pattern, $string, $matches); print_r($matches);
I get “1234”
But I get nothing when I use it in the rule.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Need Help With add_rewrite_rule Regex’ is closed to new replies.