how to show list students frontend

To list students on the frontend, you can create a shortcode in your functions.php that queries your custom wp_students table and outputs the data in a table or card layout.

// ============================
// Shortcode: List All Students
// ============================
function adc_list_students_shortcode() {
if ( function_exists(‘adc_is_rest_request’) && adc_is_rest_request() ) return; // don’t run in REST

global $wpdb;
$table_name = $wpdb->prefix . "students";

$results = $wpdb->get_results("SELECT * FROM $table_name ORDER BY roll_number ASC");

ob_start();

if ( ! empty( $results ) ) {
    echo '<h2>Student List</h2>';
    echo '<table border="1" cellpadding="8" cellspacing="0" style="border-collapse: collapse; width:100%;">';
    echo '<tr>
            <th>ID</th>
            <th>Name</th>
            <th>Class</th>
            <th>Roll No</th>
            <th>Email</th>
            <th>Phone</th>
          </tr>';

    foreach ( $results as $row ) {
        echo '<tr>';
        echo '<td>' . esc_html($row->id) . '</td>';
        echo '<td>' . esc_html($row->firstname . " " . $row->lastname) . '</td>';
        echo '<td>' . esc_html($row->class) . '</td>';
        echo '<td>' . esc_html($row->roll_number) . '</td>';
        echo '<td>' . esc_html($row->email) . '</td>';
        echo '<td>' . esc_html($row->phone) . '</td>';
        echo '</tr>';
    }

    echo '</table>';
} else {
    echo '<p>No students found.</p>';
}

return ob_get_clean();

}
add_shortcode(‘list_students’, ‘adc_list_students_shortcode’);

How it works:

  • Place this in your child theme’s functions.php or in a small plugin.
  • Add the shortcode [list_students] to any page/post → it will display a table of students.
  • Data comes directly from your custom wp_students table.

Share on Facebook Share on Twitter