add_rewrite_rule() not working

You rewrite rule is quite broad and will most likely generate a lot of conflicts. add_action(‘init’, ‘dcc_rewrite_tags’); function dcc_rewrite_tags() { add_rewrite_tag(‘%propref%’, ‘([^&]+)’); } add_action(‘init’, ‘dcc_rewrite_rules’); function dcc_rewrite_rules() { add_rewrite_rule(‘^cottage-details/(.+)/?$’,’index.php?page_id=2&propref=$matches[1]’,’top’); } Then you can access to propref query var like: $propref = get_query_var( ‘propref’ ); And remember to flush the rewrite rules; you can do it … Read more

Multiple values in a rewrite rule, is it possible?

As far I understand, you know are able to have an URL like example.com/recipes/dinner/ or example.com/recipes/lunch/ but now you also want to have an URL like example.com/recipes/dinner-lunch/ that pulls posts from both “dinner” and “lunch” courses. In currents state of WP rewrites this is not possible just with add_rewrite_rule but you also need to use … Read more

resolve /author/ to a page or archive (of all authors) template

If you use code similar to setup the rewrite rules: function ex_rewrite( $wp_rewrite ) { $feed_rules = array( ‘author/?$’ => ‘index.php?author_page=author_page’ ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; return $wp_rewrite; } // refresh/flush permalinks in the dashboard if this is changed in any way add_filter( ‘generate_rewrite_rules’, ‘ex_rewrite’ ); followed by code to add the author_page as … Read more

Using add_rewrite_rule() to redirect to Front Page

Found the solution in this thread: How to prevent the default home rewrite to a static page Just disable canonical redirect for front page: function disable_canonical_redirect_for_front_page( $redirect ) { if ( is_page() && $front_page = get_option( ‘page_on_front’ ) ) { if ( is_page( $front_page ) ) $redirect = false; } return $redirect; } add_filter( ‘redirect_canonical’, … Read more

How to change the matches in add_rewrite_rule

Rewrite rules don’t call functions like you’re asking. WordPress is far more flexible than that, because you might want to run your code at any one of an unlimited set of points in the processing of the page and not be restricted to that one specific moment in the code when the rewrite rule is … Read more

Redirect taxonomy to custom template to list terms in taxonomy

The 404 might be created because your regular expression requires the value after ‘state/’. Please try to replace: function handle_taxonomy_route() { add_rewrite_rule(‘^state/([^/]+)/?’, ‘index.php?state_var=$matches[1]’, ‘top’); } with: function handle_taxonomy_route() { add_rewrite_rule(‘^state/([^/]*)/?’, ‘index.php?state_var=$matches[1]’, ‘top’); }

Separate posts by chapter per rewrite

Since rewrite topics is something requiring tedious testing and time. And it is not something that 1 answer – 1 code complete because it involves many unknown factors from the asker such as how does the post type is created, settings in query_var which affects the query param is there any plugins involved what other … Read more

why is are these rewrite_tags and rules not working?

Your rewriterules arn’t correct anymore. You changed add_rewrite_rule(‘^video/([^/]*)/([^/]*)/[^/]*)’, ‘index.php?pagename=video&video_id=$matches[1]&video_src=$matches[2]&video_title=$matches[3]’, ‘top’); To add_rewrite_rule(‘^video/([^/]*)/([^/]*)/[^/]*)’, ‘video/&video_id=$matches[1]&video_src=$matches[2]&video_title=$matches[3]’, ‘bottom’); The correct rewriterules for your pages are: Video add_rewrite_rule(‘^video/([^/]*)/([^/]*)/[^/]*)’, ‘index.php?pagename=video&video_id=$matches[1]&video_src=$matches[2]&video_title=$matches[3]’, ‘top’); Team add_rewrite_rule(‘^videos/team/([^/]*)/([^/]*)’, ‘index.php?pagename=videos&team_id=$matches[1]&team_slug=$matches[2]’, ‘top’); League add_rewrite_rule(‘^videos/league/([^/]*)/([^/]*)’, ‘index.php?pagename=videos&league_id=$matches[1]&league_slug=$matches[2]’, ‘top’); For team and league I assumed your WordPress page is “videos”. If it is the subpage then you have to change “pagename=videos” … Read more