Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: BP 1.2: How to add a custom tab on the Home activity section


Mike Pratt
Participant

@mikepratt

Update: Here is how we use a custom field to look up a group and return it’s ID to create a custom query stream:

// passes MyClass scope into ajax query for custom Class Year activity filter
function bp_my_ajax_querystring_activity_filter( $query_string, $scope ) {
global $bp, $wpdb;

if ( $scope != 'myclass' || !is_user_logged_in() )
return $query_string;

$args = array();
parse_str( $query_string, $args );
$args['object'] = $bp->groups->id;

// get user's class year and generate slug (BN naming
convention is usma-yyyy for class groups)
$slug = "usma-". bp_get_profile_field_data( array('field'=>
'Class Year', 'user_id' => $bp->loggedin_user->id));;
$groupid = BP_Groups_Group::get_id_from_slug($slug);
$args['primary_id'] = $groupid;

return http_build_query( $args );
}
add_filter( 'bp_dtheme_ajax_querystring_activity_filter',
'bp_my_ajax_querystring_activity_filter', 1, 2 );

Every new user selects a graduating Class Year e.g. 1987 upon registration. They are auto-joined to a Class group with the naming convention ‘USMA YYYY’ (the slug is then ‘usma-yyyy’

So the $slug var is generated off a lookup of the logged in user’s Class year field and then the slug permits lookup of the Group ID. Of course, sticking to a naming convention is how this works but the concept is pretty simple.

You could easily have a custom field (required or voluntary) that provides a starting point via it’s values for custom Activity filtering. TIP: Stick to drop-downs and check boxes in order to control the values fed to the $slug function.

Skip to toolbar