where are you displaying and what is the “post”
@modemlooper I have a custom post type called auction where I display the users information but I now want to display the groups they have created within my auction listings
Thanks
There isn’t a function for that so you will have to access the database and get the info
place this in bp-custom.php
function bp_group_creator_groups( $user_id ) {
global $wpdb;
$groups = $wpdb->get_results( $wpdb->prepare( "SELECT name FROM wp_bp_groups WHERE creator_id = %d", $user_id ) );
foreach ( $groups as $group ) {
echo '<li>' . $group->name . '</li>';
}
}
then you can use this in your theme template. you will need to replace $user_id with the author of the custom posts type.
`<?php bp_group_creator_groups( $user_id ); ?>`
@modemlooper you are a champion mate!
Thank you
@designnz Just in case it’s not obvious do ensure you render that loop in ‘ul’ tags:
I would add an
if($groups) { ?>
<ul>
<?php
rest of the code here
?>
</ul>
<?php } ?>
Depends on how you want to display results. I left it with less markup just to show a more pure function. I would put most html in your theme.
function bp_group_creator_groups( $user_id ) {
global $wpdb;
$groups = $wpdb->get_results( $wpdb->prepare( "SELECT name FROM wp_bp_groups WHERE creator_id = %d", $user_id ) );
if ( $groups ) {
foreach ( $groups as $group ) {
echo '<li>' . $group->name . '</li>';
}
} else {
echo '<li>No Groups Created</li>';
}
}
Then in theme
`<ul><?php bp_group_creator_groups( $user_id ) ?></ul>`
@modemlooper , @hnla
Thanks guys, It works great.
what the best way to display a users group with all avatar and other info? I was thinking taking most of the coded from groups-loop.php?
thank you
Are one of you open to do some extra work for me? Im 5 days out from launching and got a few minor things I need help with.(paid obviously)
Let me know if your interested and i flick you the link to my site.
@designnz
You can contact me thru the info on my profile here.
@modemlooper
That works, with the addition of the else section to generate li elements for no result – although better is not to generate a list construct to render a message as it’s technically not a list. Splitting markup is never a great idea although marginal however where normally having markup in functions in core files not a great idea where one manges the function from a theme perspective I would be happy with the function generating the full rendered output which in this instance is why I suggested that approach I guess.
@designnz as @shanebp has jumped in 🙂 I’ll leave him to it
@designnz
Please give @hnla dibs, if he’s interested.
Didn’t mean to step on any toes – didn’t think those guys would be available for small jobs.
@designnz you can use the groups loop and retrieve the group id’s and then pass those to the loop.
@modemlooper ,@shanebp , @hnla
What ive done it display the groups loop in my custom post with the $group parameter but it shows all the groups instead.
Could you give an example getting it to only show the posts author’s groups?
thanks.
And really keen on giving someone some work so could whoever is free let me know. Shane I’ll be in touch.
email me modemlooper @ gmail