Custom URL Rewrite Rules not working

I encountered the same issue on a client project. If you haven’t already, you’ll need to add the query variable as a public query variable otherwise using get_query_var() won’t work properly. /** * Adds the query var to public vars, making it accessible. */ add_filter(‘query_vars’, ‘query_vars’); function query_vars($public_query_vars) { $public_query_vars[] = ‘custom_route’; return $public_query_vars; } … Read more

Custom URL rewrite with add_rewrite_rule

Updating the rewrite-rules manually as follows worked for me: function gallery_rewriterules( $wp_rewrite ) { $new_rules = array( “hochzeitsfotografen/([^/]+)/([^/]+)/?([0-9] {1,})/?” => “index.php?fotograf=”.$wp_rewrite->preg_index(1).”& gallery=”.$wp_rewrite->preg_index(2).”&img=”.$wp_rewrite->preg_index(3)); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_filter(‘generate_rewrite_rules’,’gallery_rewriterules’);