Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get group by creator_id?


  • designnz
    Participant

    @designnz

    @modemlooper , @mercime , @shanebp ,  I’ve been trying to work this out for 6 months!

     

    I want to display a users group in a single post listing outside of the groups loop but can seen to pick anything up.

    My logic is if post author is equal to creator_id then it should display.

     

    Im happy to pay for something like this as its urgent.

     

    And PS: sorry for calling you out – just know you guys are probably the most knowledgeable on here.

     

    Thanks

Viewing 13 replies - 1 through 13 (of 13 total)

  • modemlooper
    Moderator

    @modemlooper

    where are you displaying and what is the “post”


    designnz
    Participant

    @designnz

    @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

     

     

     


    modemlooper
    Moderator

    @modemlooper

    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 ); ?>`


    designnz
    Participant

    @designnz

    @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 } ?>

     


    modemlooper
    Moderator

    @modemlooper

    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>`


    designnz
    Participant

    @designnz

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


    shanebp
    Moderator

    @shanebp

    @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


    shanebp
    Moderator

    @shanebp

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


    modemlooper
    Moderator

    @modemlooper

    @designnz you can use the groups loop and retrieve the group id’s and then pass those to the loop.


    designnz
    Participant

    @designnz

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


    modemlooper
    Moderator

    @modemlooper

    email me modemlooper @ gmail

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Get group by creator_id?’ is closed to new replies.
Skip to toolbar