Hi there,
In this case you might perhaps utilize the group hierarchy and once you identify the subsets, create(if necessary) those sub-groups and add these users to each respective sub-group. Each these sub-groups should have the same parent group, the one you’re looking into for subsets.
Also worth mentioning is the moment you wish to trigger that, on user creation or when a user is added to a group.
Useful resources:
– https://developer.wordpress.org/reference/hooks/user_register/
– groups_created_user_group
– https://github.com/itthinx/groups/blob/master/lib/core/class-groups-group.php#L255
– https://github.com/itthinx/groups/blob/master/lib/core/class-groups-user-group.php#L94
Kind regards,
George
Plugin Author
Kento
(@proaktion)
I would simply approach this with an intersection:
1. Get all user IDs in that group:
$group = new Groups_Group( $group_id );
$group_user_ids = $group->user_ids;
2. Get users matching the desired time frame (*):
$period_user_ids = get_users(
array(
'fields' => 'ID',
'date_query' => array(
'compare' => 'BETWEEN',
'day' => [1,2],
'month' => [1,2],
'year' => [2022,2022]
)
)
);
3. Intersect :
$user_ids = array_intersect( $group_user_ids, $period_user_ids );
Which will give you the set of users matching both constraints.
—
(*) If you want to do the direct query instead of using get_users() with a date_query, you could do:
global $wpdb;
$user_query = $wpdb->prepare(
"SELECT ID FROM $wpdb->users WHERE user_registered >= %s AND user_registered <= %s",
'2022-01-01 00:00:00',
'2022-02-02 23:59:59'
);
$period_user_ids = $wpdb->get_col( $user_query );