WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the buddypress theme buddyboss. the main reason was that this theme is able to manage a picture gallery (which works great).

i now want to call that picture-function within the members-loop. one of the buddyboss-admins told me:

"you will need the functions from buddy_boss_pics.php. Specifically you need to use function buddyboss_pics_screen_picture_grid_content() starting from line: 285. You will need to edit the file to work with the members-loop since it currently uses displayed_user_id."

this is how the function looks:

function buddyboss_pics_screen_picture_grid_content()
    global $bp, $wpdb, $bbpics;

    $wpdb->show_errors = BUDDY_BOSS_DEBUG;

    $img_size = is_active_sidebar( 'Profile' ) ? 'buddyboss_pic_med' : 'buddyboss_pic_wide';

    $gallery_class = is_active_sidebar( 'Profile' ) ? 'gallery has-sidebar' : 'gallery';

    $user_id = $bp->displayed_user->id;
    $activity_table = $wpdb->prefix."bp_activity";
    $activity_meta_table = $wpdb->prefix."bp_activity_meta";

    $pages_sql = "SELECT COUNT(*) FROM $activity_table a INNER JOIN $activity_meta_table am ON a.id = am.activity_id WHERE a.user_id = $user_id AND meta_key = 'bboss_pics_aid'";

    $bbpics->grid_num_pics = $wpdb->get_var($pages_sql);

    $bbpics->grid_current_page = isset( $_GET['page'] ) ? (int) $_GET['page'] : 1;

    // Prepare a SQL query to retrieve the activity posts 
    // that have pictures associated with them
    $sql = "SELECT a.*, am.meta_value FROM $activity_table a INNER JOIN $activity_meta_table am ON a.id = am.activity_id WHERE a.user_id = $user_id AND meta_key = 'bboss_pics_aid' ORDER BY a.date_recorded DESC";

    buddy_boss_log("SQL: $sql");

    $pics  = $wpdb->get_results($sql,ARRAY_A);

    $bbpics->grid_pagination = new BuddyBoss_Paginated( $pics, $bbpics->grid_pics_per_page, $bbpics->grid_current_page );

    buddy_boss_log("RESULT: $pics");

    // If we have results let's print out a simple grid
    if ( !empty( $pics ) )
        $bbpics->grid_had_pics = true;
        $bbpics->grid_num_pics = count( $pics );

How should I change the function?

share|improve this question

closed as off-topic by Pieter Goosen, gmazzap, kaiser Aug 4 '14 at 16:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

You'll have to substitute $bp->displayed_user->id with bp_get_member_user_id() to make it work within the members loop.

I'm guessing that that function is used in other parts of your theme as well and changing the $user_id variable will probably screw things up, so it might be better to copy that function across to your themes functions.php file. You'll have to rename the function to avoid any conflicts, change the user id and then use your new function in the members loop.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.