Rewrite Rules and Query Vars Question
-
We’re customizing the BuddyPress groups loop to filter groups by state and all of that is working fine by passing ?state=FL in the query string. I’m now trying to add WordPress rewrite rules so I can make the url /groups/state/FL and be able to access state=FL by $wp_query->query_vars.
I’ve used the following code to accomplish this rewrite:
`function add_rewrite_rules($aRules) {
$aNewRules = array(‘groups/state/(.+)/?$’ => ‘index.php?pagename=groups&state=$matches[1]‘);
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter(‘rewrite_rules_array’, ‘add_rewrite_rules’);function wptuts_add_queryvars( $query_vars ) {
$query_vars[] = ‘state’;
return $query_vars;
}
add_filter( ‘query_vars’, ‘wptuts_add_queryvars’ );`This is all working and I can access the /groups/ page from /groups/state/FL now, except no content is displaying in the page…
Is there a better way to accomplish this using BuddyPress rewrite functions?
You must be logged in to reply to this topic.