The reason I’m looking to do this via a shortcode is that I already have a Toolset view that can produce the information on a page that I need, and I can drop in the user ids of the group manually and it works – but I want it to be dynamic so that which group it’s displayed on, it can show the correct user ids.
take a look at https://wordpress.org/plugins/bp-profile-shortcodes-extra/ in this plugin there’s a group members list shortcode, you should be able to pick up what you need from there.
Try something like this in your shortcode:
$args = array(
'group_id' => 666, // set the ID somehow
'exclude_admins_mods' => false
);
$group_members_result = groups_get_group_members( $args );
$group_members = array();
foreach( $group_members_result['members'] as $member ) {
$group_members[] = $member->ID;
}
return implode(", ", $group_members);
Check the $args
by reviewing groups_get_group_members()
in buddypress\bp-groups\bp-groups-functions.php
Thanks @venutius & @shanebp for the help.
I have it working… sort of.
I looked into the code of the plugin mentioned and was able to tweak the code to output a list of usernames separated by commas rather than the lists set by the plugin.
However, when I nest that shortcode within the Toolset Views shortcode, rather than printing the usernames to that space – the view shows posts by ALL users and not the ones returned by the shortcode grabbing the usernames.
If I copy and paste the output from the shortcode into the view directly – it works.
A demo of the page can be found here.
I don’t suppose either of you have any suggestions of where I’m going wrong?
I’ve not played with Toolset so have limited knowledge of that. I take it that it’s expecting a comma delimited list of usernames. my first question is – is it looking for the WP Username and is your list returning them correctly (as opposed to the BuddyPress fullname).
I think what I’d do first is to take the shortcode output and paste this into the Toolset shortcode manually to see if that works. If it does then it would appear the Toolset shortcode and your shortcode are not interacting properly.
@venutius
Thanks for the swift reply. I’ve got it set up so wp username and bp usernames match and when I copy the shortcode output manually back into the toolset shortcode it works fine – so it seems to be something to do with when it’s nested shortcode within shortcode. I’m using a nested shortcode plug-in to enable me to do so.
Another option I had available to me was to print the action of writing a new CPT post to the group activity stream. That worked and I put it on the live environment as well… then the next day (with no changes) the same code stopped working on both our staging and dev website and when the post was created, it submitted it to the sitewide stream rather than the groups stream.
I’d inserted that CPT activity stream code into a bp-custom.php file within the plugin directory and tested it with an account both with and without admin access.
Yes that might be easier, presumably you just need to tweak the activity_add function to make it group specific.
I think the issue with using a nesting plugin to allow nesting on shortcode within another makes it pretty difficult to get support, it could be any of the three plugins that’s not working correctly.