Site icon Hip-Hop Website Design and Development

I’m trying to display data from a custom table to users with a custom role filtered by their login

I have constructed a plugin that contains a custom DB table collecting and displaying data about of the viewing activity of users who have a custom role of ‘attendee’ on a custom post type page called ‘presentations’. I have produced a report of this activity visible to administrators as follows:

<?php
global $wpdb;
$results = $wpdb->get_results('SELECT v.user_id, v.video_id, v.last_updated, v.watch_data, u.user_login, u.user_email FROM wp_video_tracking AS v INNER JOIN wp_users AS u ON u.ID = v.user_id ORDER BY last_updated DESC');
$table_row = "";
foreach( $results as $result ) {
   $table_row .= "<tr>";
   $table_row .= "<td class='rdc-table-data'>" . $result->user_id  . "</td>";
   $table_row .= "<td class='rdc-table-data'>" . $result->user_login  . "</td>";
   $table_row .= "<td class='rdc-table-data'>" . $result->user_email  . "</td>";
   $table_row .= "<td class='rdc-table-data'>" . $result->video_name  . "</td>";
   $table_row .= "<td class='rdc-table-data'>" . $result->last_updated  . "</td>";
   $table_row .= "<td class='rdc-table-data'>" . $result->watched_percentage  . "</td>";
   $table_row .= "</tr>";
}

echo $table_row;
?>

I have a another custom role called ‘moderators’ that I would like to display the attendee viewing data for only those ‘presenatations’ for which the ‘moderator’ is assigned. Presently, I’ve created a custom field attached to these events that allows me to specify and assign the CPT to a specific user who is a ‘moderator’. How can I accomplish this?

I hope this is clear…effectively, I need to filter the custom table’s results so that they are only displayed to the logged in custom role for which the CPT is allocated. Seems like a custom join and a where clause would be in order?