Skip to content

Instantly share code, notes, and snippets.

@BhargavBhandari90
Last active May 15, 2017 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BhargavBhandari90/805fd66a7ccf75fb3823bd1036b6a833 to your computer and use it in GitHub Desktop.
Save BhargavBhandari90/805fd66a7ccf75fb3823bd1036b6a833 to your computer and use it in GitHub Desktop.
Get randome image in member's loop
<?php
// Add this function to theme's functions.php
/**
* Show randome album image in member's loop.
*/
function rtmedia_members_gallery() {
global $wpdb;
if ( function_exists( 'bp_get_member_user_id' ) ) {
// Get member's ID.
$member_id = bp_get_member_user_id();
$user_query = "SELECT * FROM `{$wpdb->prefix}rt_rtm_media` WHERE `media_author` = '{$member_id}' AND `media_type` = 'photo' ORDER BY rand() LIMIT 1";
$thumb_detail = $wpdb->get_row( $user_query );
$members_media_image = wp_get_attachment_image( $thumb_detail->media_id, 'thumbnail' );
if ( ! empty( $members_media_image ) ) {
echo $members_media_image;
}
}
}
add_action( 'bp_directory_members_actions', 'rtmedia_members_gallery' );
?>
// Add this to custom css ( rtMedia->settings->Custom CSS )
#buddypress ul.item-list li .item {
float: left !important;
width: 55% !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment