I have defined a rewrite rule for a subpage 'vehiculo' (which is a template-page in my theme folder), and subpage of 'vehiculos', because I want a pretty URL and the code is handled in the template file. So the target is to handle https://mydomain.cl/vehiculos/vehiculo/1599 as https://mydomain.cl/vehiculos/vehiculo/?auto-id=1599 or https://mydomain.cl/index.php?pagename=vehiculo&auto-id=1599
function query_vars_filter($vars) {
$vars[] = 'id';
$vars[] = 'auto-id';
return $vars;
}
add_filter( 'query_vars', 'query_vars_filter' );
function custom_rewrite_rule() {
add_rewrite_rule('vehiculos/vehiculo/([^/]*)','index.php?pagename=vehiculo&auto-id=$matches[1]','top');
//https://mydomain.cl/index.php?pagename=vehiculo&auto-id=1599
}
add_action('init', 'custom_rewrite_rule', 10, 0);
insofar the rewrite should theoretically work, as the rewrite analyzer shows:
Also when I paste the URL https://mydomain.cl/index.php?pagename=vehiculo&auto-id=1599 manually into the browser it gives me the right result. I have made the code so flexible that https://mydomain.cl/vehiculos/vehiculo/?auto-id=1599 also works
So far, so good, right? Now the crux is: if I browse to https://mydomain.cl/vehiculos/vehiculo/1599 The correct page is shown, but somehow the parameter 1599 is lost. I var dumped the query string, get params and apparently 'auto-id' is nowhere found, which is a complete mistery to me.
$_GET = array(0) { } $wp_query->query_vars = array(66) { ["page"]=> int(0) ["pagename"]=> string(8) "vehiculo" ["error"]=> string(0) "" ["m"]=> string(0) "" ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" ["subpost_id"]=> string(0) "" ["attachment"]=> string(0) "" ["attachment_id"]=> int(0) ["name"]=> string(8) "vehiculo" ["page_id"]=> int(0) ["second"]=> string(0) "" ["minute"]=> string(0) "" ["hour"]=> string(0) "" ["day"]=> int(0) ["monthnum"]=> int(0) ["year"]=> int(0) ["w"]=> int(0) ["category_name"]=> string(0) "" ["tag"]=> string(0) "" ["cat"]=> string(0) "" ["tag_id"]=> string(0) "" ["author"]=> string(0) "" ["author_name"]=> string(0) "" ["feed"]=> string(0) "" ["tb"]=> string(0) "" ["paged"]=> int(0) ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["preview"]=> string(0) "" ["s"]=> string(0) "" ["sentence"]=> string(0) "" ["title"]=> string(0) "" ["fields"]=> string(0) "" ["menu_order"]=> string(0) "" ["embed"]=> string(0) "" ["category__in"]=> array(0) { } ["category__not_in"]=> array(0) { } ["category__and"]=> array(0) { } ["post__in"]=> array(0) { } ["post__not_in"]=> array(0) { } ["post_name__in"]=> array(0) { } ["tag__in"]=> array(0) { } ["tag__not_in"]=> array(0) { } ["tag__and"]=> array(0) { } ["tag_slug__in"]=> array(0) { } ["tag_slug__and"]=> array(0) { } ["post_parent__in"]=> array(0) { } ["post_parent__not_in"]=> array(0) { } ["author__in"]=> array(0) { } ["author__not_in"]=> array(0) { } ["search_columns"]=> array(0) { } ["ignore_sticky_posts"]=> bool(false) ["suppress_filters"]=> bool(false) ["cache_results"]=> bool(true) ["update_post_term_cache"]=> bool(true) ["update_menu_item_cache"]=> bool(false) ["lazy_load_term_meta"]=> bool(true) ["update_post_meta_cache"]=> bool(true) ["post_type"]=> string(0) "" ["posts_per_page"]=> int(10) ["nopaging"]=> bool(false) ["comments_per_page"]=> string(2) "20" ["no_found_rows"]=> bool(false) ["order"]=> string(4) "DESC" }
Any clou why that happens? where could the auto-id be? Is it lost because there's a second rewrite rule matching?