[buddypress-trac] [BuddyPress Trac] #9031: bp_has_groups has missing parameter to fetch groups based on the group's creator or admin

buddypress-trac noreply at wordpress.org
Fri Dec 1 20:21:50 UTC 2023


#9031: bp_has_groups has missing parameter to fetch groups based on the group's
creator or admin
-------------------------+---------------------
 Reporter:  vapvarun     |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  11.5.0
Component:  Groups       |     Version:  11.4.0
 Severity:  normal       |  Resolution:
 Keywords:               |
-------------------------+---------------------

Comment (by vapvarun):

 got a workaround by creating a list using SQL for the creator_id
 {{{#!php
 function vap_get_created_groups_by_user($user_id) {
     global $wpdb;
     $bp = buddypress();

     // Modify the SQL to select only the 'id' column
     $sql = $wpdb->prepare(
         "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d",
         $user_id
     );

     // Fetch and return the results
     $results = $wpdb->get_results($sql);

     // Extract just the group IDs from the results
     $group_ids = array_map(function($group) {
         return $group->id;
     }, $results);

     // Convert the array of IDs into a comma-separated string
     return $group_ids;
 }
 }}}

 and then sending the same as the argument using the included parameter

 {{{#!php
 <?php
 $args = array('include' =>  $group_ids); // Modify this according to your
 needs
 }}}

 Using bp_has_groups() twice with different parameters inside a custom tab
 and the loop template can cause conflicts or unintended behavior.
 Having a custom template for group-loop was necessary to achieve the
 desired result.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/9031#comment:1>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list