I've been trying to adapt the rewrite functions described here with little success:
The structure of the URL I'd like to achieve is
/academics/faculty/profile/faculty-member
Where /academics is the blog, faculty is the page, and profile is the child page of profile. If you use this:
/academics/faculty/profile?fid=faculty-member
It displays the faculty profile, no problem. What I want is to assign fid as a rewrite that cleans up the variable from the URL and leaves only the faculty member.
I've rewritten the function so that the add_rewrite_rule looks like this:
// Register the variables that will be used as parameters on the url
function add_my_var($public_query_vars) {
$public_query_vars[] = 'fid';
return $public_query_vars;
}
add_filter('query_vars', 'add_my_var');
// Build the rewrite rules, for the extra parameter
function do_rewrite() {
add_rewrite_rule('(faculty/profile)/[/]?([^/]*)$', 'index.php?pagename=profile&fid=$matches[1]','top');
}
add_action('init', 'do_rewrite');
// The parameter is now accessible
get_query_var('fid') ;
I thought I was following the directions accurately, and I've flushed the permalink structure, but when I try to use the new URL it just reverts to /academics/faculty/profile and spits nothing out, even when I add:
$profile2 = get_query_var('fid') ;
to the page template.
Is my rewrite accurate? Any idea why it would work in the prior examples but not here?