bp_dd_get_random_groups_ids( int $count = 1, string $output = 'array' )
Get the array (or a string) of group IDs.
Description
Parameters
- $count
-
(Optional) If you need all, use 0.
Default value: 1
- $output
-
(Optional) What to return: 'array' or 'string'. If string - comma separated.
Default value: 'array'
Return
(array|string) Default is array.
Source
File: bp-core/bp-core-tools-default-data.php
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | function bp_dd_get_random_groups_ids( $count = 1, $output = 'array' ) { $groups_arr = ( array ) bp_get_option( 'bp_dd_imported_group_ids' ); if ( ! empty ( $groups_arr ) ) { $total_groups = count ( $groups_arr ); if ( $count <= 0 || $count > $total_groups ) { $count = $total_groups ; } // Get random groups. $random_keys = ( array ) array_rand ( $groups_arr , $count ); $groups = array (); foreach ( $groups_arr as $key => $value ) { if ( in_array( $key , $random_keys ) ) { $groups [] = $value ; } } } else { global $wpdb ; $bp = buddypress(); $limit = '' ; if ( $count > 0 ) { $limit = 'LIMIT ' . (int) $count ; } $groups = $wpdb ->get_col( "SELECT id FROM {$bp->groups->table_name} ORDER BY rand() {$limit}" ); } /** * Convert to integers, because get_col() returns array of strings. */ $groups = array_map ( 'intval' , $groups ); if ( $output === 'string' ) { return implode( ',' , $groups ); } return $groups ; } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.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.