Add rewrite rule to Buddypress members component
-
I was trying to create a link to display only online members on the members directory. At first I was able to achieve that by adding query string to members directory permalink:
mysite.com/members/?type=online
and then catching this var and modifying theme query string accordingly:
add_filter('bp_dtheme_ajax_querystring', 'ad_theme_ajax_querystring', 10, 2); function ad_theme_ajax_querystring ($qs, $object) { if ($object != 'members') return $qs; if ( isset($_GET['type']) && $_GET['type'] == 'online' ) { if ($qs != '') { if (false !== strpos($qs, 'type')) { $qs = preg_replace("/type=(active|random|newest|popular|alphabetical)/", "type=online", $qs); } else { $qs .= '&type=online'; } } else { $qs = 'type=online'; } } return $qs; }
But now I would like to create a pretty permalink for that:
mysite.com/members/online/
So I added the rewrite rule using add_rewrite_endpoint like:
add_action('init', 'ad_rewrite_online_members'); function ad_rewrite_online_members() { add_rewrite_endpoint('online', EP_ALL); } // setup 'online' query var add_filter('request', 'ad_request'); function ad_request($vars) { if (isset($vars['online'])) $vars['online'] = true; return $vars; }
and using same query string filter above, but with
if (get_query_var('online'))
instead of
if (isset($_GET['type']) && $_GET['type'] == 'online')
But now when visiting
mysite.com/members/online/
I get a 404 error page, the same code is working on another WP installation without Buddypress, so I figured this is caused by BP but could not find out what need to be done to make BP recognize my new permalink.So what is the proper way to add new permalink rules that will be recognized by BP? Any help or further resources would be highly appreciated.
Thanks.
- The topic ‘Add rewrite rule to Buddypress members component’ is closed to new replies.