Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Kathy Williams

Display BP Group column

Authors are users in WordPress. For a custom post type, in the list view, I have the Author displayed in one column. However, I also want to display that Author’s (aka; User) BuddyPress Group(s). I attempted to install the BuddyPress Columns integration plugin, but it says that it’s no longer needed with Admin Columns Pro. Yes, the User’s groups show in the Users interface, and I can modify the Users interface to show the BuddyPress columns. But that doesn’t extend to other areas where the User metadata could/should be available.
How do I accomplish this? I understand that it needs to match the Author/User to their ID, and then query the bp_groups_members table for that ID; and then further query the bp_groups table for the Name that matches those IDs.

1 week, 4 days ago
Stefan van den Dungen Gronovius
Developer

Thanks for your message.

We intentionally chose not to include all available user fields in related user columns on list tables other than the Users table. However, there are hooks available that allow you to modify the value.

In the snippet below, the value is changed when using the Author column (the custom one from our plugin) and the display setting is set to ID. It will then show the Groups related to the selected author/user.

add_filter('ac/column/render', static function (string $value, AC\Column\Context $column) {
    if ($column->get_type() !== 'column-author_name' && $column->get('display_author_as') !== 'ID') {
        return $value;
    }

    $groups = [];
    foreach (groups_get_user_groups($value)['groups'] as $group_id) {
        $group = groups_get_group($group_id);

        if ($group instanceof BP_Groups_Group) {
            $groups[] = $group->name;
        }
    }

    return implode(', ', $groups);
}, 10, 3);

Of course, you can adjust the guard condition to check for more specific column properties, such as a particular column name or ID.

More information about the hook and other examples can be found here:
https://github.com/codepress/admin-columns-hooks/blob/master/ac-column-render.php

1 week, 3 days ago

You must be logged in to reply to this topic.