After lots of pulling my hair out I figured out the problem.
I needed to use the add_rewrite_tag() function to tell wordpress to allow my query vars.
function prefix_movie_rewrite_rule() {
add_rewrite_tag('%state_id%', '([A-Za-z0-9\-\_]+)');
add_rewrite_tag('%state%', '([A-Za-z0-9\-\_]+)');
add_rewrite_rule ( 'states/([A-Za-z0-9\-\_]+)/([A-Za-z0-9\-\_]+)', 'index.php?
state_id=$matches[1]&state=$matches[2]', 'top' );
}
add_action( 'init', 'prefix_movie_rewrite_rule');
Related Posts:
- Making extra parameters optional
- What add_rewrite_tag()’s RegEx matches against?
- add_rewrite_rule isnt working, not getting added to rules array, why?
- Making extra parameters optional
- Why isn’t my rewrite rule working when there is no second parameter?
- When should add_rewrite_tag() be used?
- add_rewrite_rule() vs $wp_rewrite->rules vs ‘rewrite_rules_array’?
- How to check if a rewrite rule exists
- Custom post types and custom variables — add_rewrite_tag() question
- add_rewrite_rule not producing anything in $_GET
- WordPress Custom URL Rewrites
- Case-insensitive add_rewrite_rules in WordPress functions
- Does add_rewrite_rule(..) only accept “index.php” as redirect target?
- Cyrillic characters in rewrite rules cause 404 Not Found errors
- Custom Endpoint Gives 404 Header
- Clean URLs for custom $_GET variables
- flush_rewrite_rules() cancels the effect of add_rewrite_rule()
- Separate posts by chapter per rewrite
- Multiple values in a rewrite rule, is it possible?
- add_rewrite_rule parameter is not received by the page
- add_rewrite_rules prefix everything
- Can someone explain the function of the third parameter of “add_rewrite_tag”
- get_query_var with add_rewrite_rule and add_filter(‘query_vars’) not working
- Reading Settings -> Front Page displays “Static Page” being reset
- add_rewrite_rule query_var not being set
- How to properly rewrite url by custom var
- why does add_rewrite_rule refresh and loose url variables
- Custom Rewrite rule to match anything not already matched by WordPress
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Add Rewrite Endpoint to CPT Archive
- Optional all capture groups in rewrite rule
- Rewrite rule : custom post type with 2 numeric variiables
- Does it still make sense using json endpoint ep_mask now that there’s the new rest api? [closed]
- Simple page URL rewrite with add_rewrite_rule()
- Hooking “delete_option_rewrite_rules” for rewrite rule addition
- Custom URL rewrites work, but break my permalinks
- WordPress shows front page, when it should show 404 with pagination style urls
- Displaying Post with Custom URL with RewriteRule or add_rewrite_rule
- Rewrite rule problem
- add_rewrite_rule redirects if value = 1
- Pass query vars to front page
- add_rewrite_rule permalinks break in WordPress 4.5
- Rewrite rule for path of favicon.ico ( Add_rewrite_rule function possible ? )
- FLUSH_REWRITE_RULES – after or before REGISTER_POST_TYPE?
- Using get_query_var() from a plugin
- How to flush rewrite rules on the activation of any plugin
- Rewrite without query parameter
- WordPress CPT slug and page slug conflicts
- Mod_rewritte – remove ?m=1 from url
- Rewrite Rule for Post Meta
- WooCommerce – Conditional for page created by rewrite_rule
- Rewrite rules priority
- Rewrite rules ignored
- How do I turn off the blog and archives?
- Add_rewrite_rule doesn’t seem to work?
- Grab last part of the url inside rule
- Leverage WP_Rewrite to pre-validate links / detect invalid links
- WordPress rewrite rule doesn’t work unless post category is explicitly called in regex
- When request has multiple matching rewrite rules, and matched rule returns 404 – iterate to next rewrite rule
- WordPress add a rewrite rule to a page to accept a GET variable
- “/” URLs without trailing slash shows 404
- How can I resolve search error with pagination wordpress
- CPT – Nice url with add_rewrite_rule
- Rewrite rule regex help required
- WordPress Own Rewrite Rules
- get_author_posts_url() doesn’t return the author URL, because of wrong author_structure
- add_rewrite_rule only works when flush first
- Homepage rewrite rule
- custom rewrite rules will not be added to wordpress rewrite_rules database
- rewrite rules problem with #comments-2345
- How to add rewrite rule for product compare page?
- Overcoming a complex WordPress page rewrite rules request
- Why isn’t my rewrite rule for add_rewrite_rule not working as expected?
- Custom Fields Query Vars and Rewrite not working
- A part of regular expression in add_rewrite_rule function not working
- Complex rewrite rules with multiple variables, some the same
- how to use mutliple add_rewrite_rule?
- Social sharing conflict with Rewrite rules
- Last query_var not working with rewritten URL
- Rewire Rules Front Page
- Rewrite permalink to include multiple taxonomies
- How to use endpoint, but remove/rewrite endpoint base?
- WordPress URL rewrite after changing web from Joomla
- add_rewrite_rule doesn’t work for me
- Rewritten URL not loading WordPress environment
- Changing default slug of post to the post id
- Rewriting base name Taxonomy same Post Type
- Where to hook to bypass instantiating WP_Query?
- Rewrite Rule & Regex – Extract ‘cat-name’ and ‘page-number’ from http://domain.com/custom-post-type/category/cat-name/page/page-number
- How to Add Rewrite Ruled Argument Into Permalink Properly
- Overwrite WP’s default search rule to redirect to my own template
- add_rewrite_rule() driving me crazy, rewrite not working when analyzer says it should
- Redirect to a file in a WordPress theme directory
- What is the `rewrite_rules` option the options table in the WordPress database?
- Direct domain alias to a specific WordPress page without the page in the URL
- rewriteRules WP6
- Standard Regex syntax doesn’t work in WordPress rewrite rule
- WordPress rewrite rule – not able to access second and third parameters
- Custom URL Rewrite Rules not working
- How to combine nearly identical custom rewrite rules for WordPress