Skip to:

Rewrite Rules and Query Vars Question

  • adambware


    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?

Viewing 2 replies - 1 through 2 (of 2 total)

  • adambware


    I see that the bp_uri filter is run before handling $_GET variables.. Might this help me accomplish my goal here?

    BuddyPress currently doesn’t make use of rewrite rules or query vars to handle its page routing. BP literally cuts up the URL, so it might see “state” as the name of a group. I can’t think of the best way to handle this at the moment.

    I assume this filter affects the group directory. I think you’re right about poking in bp_uri; you need to unset the part of current_action (maybe?) so BP stops trying to load a group.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rewrite Rules and Query Vars Question’ is closed to new replies.
Skip to toolbar