BP_Group_Member_Query::get_gm_ids_ordered_by_activity( BP_User_Query $query, array $gm_ids = array() )
Sort user IDs by how recently they have generated activity within a given group.
Description
Parameters
- $query
-
(Required) BP_User_Query object.
- $gm_ids
-
(Optional) array of group member ids.
Default value: array()
Return
(array)
Source
File: bp-groups/classes/class-bp-group-member-query.php
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | public function get_gm_ids_ordered_by_activity( $query , $gm_ids = array () ) { global $wpdb ; if ( empty ( $gm_ids ) ) { return $gm_ids ; } if ( ! bp_is_active( 'activity' ) ) { return $gm_ids ; } $activity_table = buddypress()->activity->table_name; $sql = array ( 'select' => "SELECT user_id, max( date_recorded ) as date_recorded FROM {$activity_table}" , 'where' => array (), 'groupby' => 'GROUP BY user_id' , 'orderby' => 'ORDER BY date_recorded' , 'order' => 'DESC' , ); $sql [ 'where' ] = array ( 'user_id IN (' . implode( ',' , wp_parse_id_list( $gm_ids ) ) . ')' , 'item_id = ' . absint( $query ->query_vars[ 'group_id' ] ), $wpdb ->prepare( "component = %s" , buddypress()->groups->id ), ); $sql [ 'where' ] = 'WHERE ' . implode( ' AND ' , $sql [ 'where' ] ); $group_user_ids = $wpdb ->get_results( "{$sql['select']} {$sql['where']} {$sql['groupby']} {$sql['orderby']} {$sql['order']}" ); return wp_list_pluck( $group_user_ids , 'user_id' ); } |
Changelog
Version | Description |
---|---|
BuddyPress 2.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.