How to filter users who did not pass test at Report?
-
Hello there,
I have written to email support, but this is a better place to start a discussion.We use turot to create a quiz for our employees.
Each employee can take the quiz more than once, but must pass the quiz at least once.
How can we filter WordPress users who haven’t taken the quiz or haven’t passed it even once?
Here is an approach that I have tried:
(but it das not working).<?php /* Plugin Name: Employee Test Report Description: Generates a report of employees who haven't taken or passed the test using Tutor plugin. Version: 1.0 Author: Boris K. */ // Add a custom admin menu item function employee_test_report_menu() { add_menu_page( 'Employee Test Report', 'Employee Test Report', 'manage_options', 'employee-test-report', 'display_employee_test_report' ); } add_action('admin_menu', 'employee_test_report_menu'); // Function to display the employee test report function display_employee_test_report() { global $wpdb; // Get all users $users = get_users(); // Initialize an array to store users who haven't taken or passed any quizzes $users_not_taken_or_passed_quiz = array(); // Loop through each user foreach ($users as $user) { // Check if the user has quiz results metadata $quiz_results = get_user_meta($user->ID, 'quiz_results', true); // If the user doesn't have quiz results metadata, add them to the array if (!$quiz_results) { $users_not_taken_or_passed_quiz[] = $user; } } // Display the results echo '<div class="wrap">'; echo '<h1>Employees Who Haven\'t Taken or Passed the Test</h1>'; if (!empty($users_not_taken_or_passed_quiz)) { echo '<table class="widefat">'; echo '<thead><tr><th>User ID</th><th>Username</th><th>Email</th></tr></thead>'; echo '<tbody>'; foreach ($users_not_taken_or_passed_quiz as $user) { echo '<tr>'; echo '<td>' . $user->ID . '</td>'; echo '<td>' . $user->user_login . '</td>'; echo '<td>' . $user->user_email . '</td>'; echo '</tr>'; } echo '</tbody>'; echo '</table>'; } else { echo '<p>No employees found who haven\'t taken or passed the test.</p>'; } echo '</div>'; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to filter users who did not pass test at Report?’ is closed to new replies.