Problems with add_rewrite_rule() regex
-
I had this working fine with two tags, but after deleting one, it doesn’t seem to work. I’ve tried so many different combinations of regex, I’m starting to wonder if it ever worked. I have the following code:
/** * Rewrite tags for plugin */ function dcc_rewrite_tags() { add_rewrite_tag('%propref%', '([^&]+)'); } add_action('init', 'dcc_rewrite_tags', 10, 0); /** * Rewrite rules for plugin */ function dcc_rewrite_rules() { add_rewrite_rule('^cottage-details/([^/]*)/?', 'index.php?p=2&propref=$matches[1]', 'top'); } add_action('init', 'dcc_rewrite_rules', 10, 0);
There is a property reference passed in the last part of the URL, eg, https://mysite.com/cottage-details/G638/ I need to pass the G638 into an array for my plugin. What I have above is calling the cottage-details page, but removing the last part of the URL, so it’s just showing as https://mysite.com/cottage-details/ and showing an empty page, rather than the information I wish to retrieve from the server. If I use https://mysite.com/cottage-details/?propref=G638, it works perfectly.
- The topic ‘Problems with add_rewrite_rule() regex’ is closed to new replies.