Skip to:
Content

BuddyPress.org

Opened 15 months ago

Last modified 6 months ago

#9031 new enhancement

bp_has_groups has missing parameter to fetch groups based on the group's creator or admin

Reported by: vapvarun's profile vapvarun Owned by:
Milestone: Awaiting Contributions Priority: normal
Severity: normal Version: 11.4.0
Component: Groups Keywords: needs-patch needs-unit-tests
Cc:

Description

During our client assistance, we came across an issue wherein we were unable to list groups using the bp_has_groups function based on the group's creator or admin.

The function accepts several parameters to filter the groups, such as 'user_id', 'group_id', 'search_terms', etc. However, none of these parameters directly allow you to filter groups based on the group's creator or admin.

The user_id parameter determines the results you will see based on the groups you have joined..

https://buddypress.org/support/topic/filter-groups-by-admin-owner/

Change History (6)

#1 @vapvarun
15 months ago

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
$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.

Last edited 15 months ago by vapvarun (previous) (diff)

#2 @imath
15 months ago

  • Milestone changed from 11.5.0 to Up Next

Thanks for your report @vapvarun let's talk about it during next dev cycle.

#3 @imath
14 months ago

  • Milestone changed from Up Next to 14.0.0

#4 @espellcaste
12 months ago

  • Milestone changed from 14.0.0 to Up Next

#5 @imath
7 months ago

  • Milestone changed from Up Next to 15.0.0

#6 @espellcaste
6 months ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from 15.0.0 to Awaiting Contributions
Note: See TracTickets for help on using tickets.