LMS & eLearning

Add Custom Columns to the LearnDash Assignments List

Add a file-type column, a learner group column and a days-waiting column to the LearnDash assignments admin list with the learndash_listing_columns filter, using the meta keys assignments actually store.

Add Custom Columns to the LearnDash Assignments List

The assignments list in the LearnDash admin shows the learner, the status and points, the course and the lesson or topic. Graders working through a queue usually want more: what kind of file was uploaded, which group the learner belongs to, and how long the submission has been waiting. LearnDash 4.18.0.1 builds that list through its own listing class with a filter for the column set, so the extra columns slot in next to the native ones instead of being tacked on at the end. This article adds the three columns above and explains the meta keys they read.

How LearnDash lists assignments

Every LearnDash post type list is driven by a subclass of Learndash_Admin_Posts_Listing in includes/admin/class-learndash-admin-posts-listing.php. The assignments subclass defines three columns, approval_status labelled Status / Points, course and lesson_topic, each as an array with a label, an after key naming the column it follows, a display callable, and optionally required. Before registering them the parent runs apply_filters( 'learndash_listing_columns', $this->columns, $this->post_type ), then hooks the core manage_edit-{post_type}_columns filter at priority 50 to insert the headers. When a cell is rendered, the class looks up the column by key and calls its display callable with the post ID and the column name.

Because the filter passes the post type, one callback can serve all LearnDash lists; check for sfwd-assignment before adding assignment-specific columns. The admin hooks reference lists the companion filters for selectors and query vars.

What an assignment stores

When a learner uploads, includes/ld-assignment-uploads.php creates an sfwd-assignment post with the learner as post_author and writes meta for file_name, file_link, file_path, user_name, disp_name, course_id, lesson_id, lesson_title, lesson_type and points. Approval adds approval_status. The post date is the upload time, which is what the waiting column uses. The assignment functions guide covers the helpers around these keys.

The snippet

<?php
/**
 * Extra columns for the LearnDash assignments list.
 */
add_filter(
    'learndash_listing_columns',
    function ( $columns, $post_type ) {
        if ( 'sfwd-assignment' !== $post_type ) {
            return $columns;
        }

        $columns['wwc_file_type'] = array(
            'label'   => __( 'File', 'wwc' ),
            'after'   => 'approval_status',
            'display' => 'wwc_assignment_column_file_type',
        );

        $columns['wwc_group'] = array(
            'label'   => LearnDash_Custom_Label::get_label( 'group' ),
            'after'   => 'course',
            'display' => 'wwc_assignment_column_group',
        );

        $columns['wwc_waiting'] = array(
            'label'   => __( 'Waiting', 'wwc' ),
            'after'   => 'lesson_topic',
            'display' => 'wwc_assignment_column_waiting',
        );

        return $columns;
    },
    10,
    2
);

function wwc_assignment_column_file_type( $post_id, $column_name ) {
    $file_name = (string) get_post_meta( $post_id, 'file_name', true );
    $extension = strtolower( pathinfo( $file_name, PATHINFO_EXTENSION ) );

    echo $extension ? esc_html( strtoupper( $extension ) ) : '&mdash;';
}

function wwc_assignment_column_group( $post_id, $column_name ) {
    $author_id = (int) get_post_field( 'post_author', $post_id );
    $group_ids = array_map( 'absint', (array) learndash_get_users_group_ids( $author_id ) );

    if ( empty( $group_ids ) ) {
        echo '&mdash;';
        return;
    }

    $titles = array_filter( array_map( 'get_the_title', $group_ids ) );
    echo esc_html( implode( ', ', $titles ) );
}

function wwc_assignment_column_waiting( $post_id, $column_name ) {
    if ( get_post_meta( $post_id, 'approval_status', true ) ) {
        echo esc_html__( 'Approved', 'wwc' );
        return;
    }

    $uploaded = get_post_time( 'U', true, $post_id );
    $days     = (int) floor( ( time() - $uploaded ) / DAY_IN_SECONDS );
    $class    = $days >= 7 ? 'wwc-waiting-late' : '';

    printf(
        '<span class="%1$s">%2$s</span>',
        esc_attr( $class ),
        esc_html( sprintf( /* translators: %d: days */ _n( '%d day', '%d days', $days, 'wwc' ), $days ) )
    );
}

add_action(
    'admin_head-edit.php',
    function () {
        if ( 'sfwd-assignment' !== get_current_screen()->post_type ) {
            return;
        }
        echo '<style>.wwc-waiting-late{color:#b32d2e;font-weight:600}</style>';
    }
);

Each column's after key places it next to a native column, so File sits beside Status / Points and Waiting sits after the lesson column. Display callbacks echo their output, matching how LearnDash's own callbacks behave. Submissions older than a week are highlighted; change the threshold to match your grading service level.

Making a column sortable

Sorting needs the core hooks rather than the LearnDash filter. Register the key with manage_edit-sfwd-assignment_sortable_columns and, in pre_get_posts for that screen, set orderby to meta_value with the relevant meta_key. The waiting column sorts naturally by date, which the list already offers through the Date column; the file type column would need a stored extension meta to sort on, written on learndash_assignment_uploaded, since file_name sorts alphabetically by name rather than by type.

Filtering by the new data

LearnDash's listing class also exposes learndash_listing_selectors for the dropdown filters above the table. The assignments list already has selectors for author, approval status, group, course and lesson, so the group column above is for scanning rather than filtering; the existing Group selector narrows the list. Adding a selector for file type follows the same array format as the native ones, with a listing_query_function that adds a meta query, and is worth doing once the extension is stored as its own meta key.

Group leaders

Group leaders see the assignments list limited to their learners, which LearnDash applies in the listing query, and the columns above render the same for them. The group column shows all of a learner's groups, including ones the leader does not administer; if that is a concern, intersect the IDs with learndash_get_administrators_group_ids( get_current_user_id() ) before printing.

Linking straight to the file

The native Status / Points column already links the uploaded file, but graders often want the link beside the file type. The file_link meta holds the public URL LearnDash generated at upload time; print it as an anchor with download set so the browser saves rather than opens it, and escape with esc_url(). If uploads were moved to a protected directory, use the file_path meta through your own download handler instead, since the stored link would no longer resolve.

Points awarded

When the lesson awards assignment points, approval stores the grader's value in the points meta, and the Status / Points column shows it together with the maximum from the lesson setting. A dedicated numeric column makes the list sortable by score once registered through the sortable columns hooks with points as the meta key, which is the one case in this article where sorting works without storing anything extra, because the value is already its own meta row.

Testing

  1. Upload a PDF as a learner in a group and confirm the list shows PDF, the group name and 0 days.
  2. Change the post date of a test assignment to ten days ago and confirm the Waiting cell turns red.
  3. Approve it and confirm the cell reads Approved.
  4. Open the lessons list and confirm no extra columns appear there, because of the post type check.

When to get help

Three columns are an hour's work. A grading workflow with assignment states, reviewer assignment and reminders is a larger build that our LearnDash services team delivers alongside the pending assignments dashboard widget; a LearnDash developer can also add the stored meta that makes the new columns sortable and filterable.

Frequently asked questions

Which filter adds columns to LearnDash admin lists?

learndash_listing_columns, which receives the column array and the post type. Each column needs a label, an after key and a display callable.

Where is the uploaded file name stored?

In the file_name post meta of the assignment, alongside file_link and file_path.

Can the new columns be sorted?

Only through the core sortable columns hooks with a meta key to sort on. Store derived values such as the extension as their own meta to make that possible.

Do the columns show for group leaders?

Yes. The list is already limited to their learners, and the columns render the same.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.