Query vars don’t end up in $_GET
, use get_query_var()
to fetch or check the value of your custom query vars set by rewrite rules.
Your rule is currently returning employees
as employees_slug
because your rule has two capture groups, so employees_slug
is held in $matches[2]
, not $matches[1]
. The first capture group is unnecessary though, so the parens can be removed.
To apply a template, you can filter page_template
and check for the presence of your query var.
function wpd_employees_page_template( $template ){
if( get_query_var( 'employees_slug' ) ){
$template = locate_template( 'employees.php' );
}
return $template;
}
add_filter( 'page_template', 'wpd_employees_page_template' );
Also note that a slightly simpler way to add a rule is via add_rewrite_rule
hooked to the init
action rather than filtering rewrite_rules_array
.