# LearnDash: Students Column on the Courses Screen

> Adds a "Students" column to the LearnDash Courses list showing how many users are enrolled in each course, cached for speed.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: learndash, admin, reporting
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/learndash-students-column-on-courses/

## Code

```php
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
    return;
}

add_filter( 'manage_sfwd-courses_posts_columns', function ( $columns ) {
    $columns['wpide_ld_students'] = 'Students';

    return $columns;
} );

add_action( 'manage_sfwd-courses_posts_custom_column', function ( $column, $course_id ) {
    if ( 'wpide_ld_students' !== $column ) {
        return;
    }

    $key   = 'wpide_ld_students_' . $course_id;
    $count = get_transient( $key );

    if ( false === $count ) {
        $query = new WP_User_Query( array(
            'fields'      => 'ID',
            'number'      => 1,
            'count_total' => true,
            'meta_key'    => 'course_' . (int) $course_id . '_access_from',
            'meta_compare' => 'EXISTS',
        ) );
        $count = $query->get_total();
        set_transient( $key, $count, 6 * HOUR_IN_SECONDS );
    }

    echo esc_html( number_format_i18n( (int) $count ) );
}, 10, 2 );

add_action( 'learndash_update_course_access', function ( $user_id, $course_id ) {
    delete_transient( 'wpide_ld_students_' . (int) $course_id );
}, 10, 2 );
```

## Notes

Counts direct enrollments; students who only get access through a group, or courses set to "Open", are not included. Counts refresh every 6 hours.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: Students Column on the Courses Screen" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
