BuddyBoss Home – Web › Support Forums › Plugins › BuddyBoss Media › Display photos count in member header
- This topic has 5 replies, 2 contibutors, and was last updated 9 years, 2 months ago by Alyssa.
Question
August 19, 2015 at 3:17 pm #44735@surfbuddyHey guys, how can I display the photos count next to followers/following in member header?
Answers
August 22, 2015 at 3:34 pm #44912@alyssa-buddyboss
AlyssaParticipant@surfied unfortunately we do not have a function for this but this might work; add this function to functions.php:
function buddyboss_member_photo_count(){ global $wpdb, $bp; if ( ! isset( $bp->displayed_user->id ) && ! is_admin() ) { return; } $photos_user_id = isset( $bp->displayed_user->id ) ? $bp->displayed_user->id : ''; $new_sql = "SELECT COUNT(id) FROM {$wpdb->prefix}buddyboss_media WHERE media_author = %d"; $sql = $wpdb->prepare( $new_sql, $photos_user_id ); $photos_cnt = $wpdb->get_var( $sql ); echo $photos_cnt; }
Then use that function wherever you want to display the photo count. They styling is left up to you 😉
August 22, 2015 at 11:00 pm #44931@surfbuddyThanks @tjchester! I added that to my child themes function.php and added the following to line 87 of members/single/member-header.php, but the count is incorrect and showing as zero.
<a href="<?php bp_displayed_user_link(); ?>photos"> <span> <p><?php echo (int) $photos_cnt["buddyboss_media"]; ?></p> <p><?php _e("Photos","boss"); ?></p> </span></a>
August 23, 2015 at 7:32 am #44950@alyssa-buddyboss
AlyssaParticipant@surfied Instead of this:
echo (int) $photos_cnt["buddyboss_media"];
simply this function, no need to echo:
buddyboss_member_photo_count();
August 24, 2015 at 12:45 pm #45050@surfbuddyWorks perfectly now! Thanks @tjchester!
August 25, 2015 at 7:34 am #45115@alyssa-buddyboss
AlyssaParticipant🙂
- The question ‘Display photos count in member header’ is closed to new replies.