Browse: Home / Snippets /

Change order of courses depending on Group ID

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

/**
 * Change course order for a specific group
 * Replace case 123 with your actual group ID
 */
add_filter( 'learndash_group_courses_order', function( $group_courses_args, $group_id ) {
    // Replace each case with your actual group ID
    switch( $group_id ) {
        case 123: // replace 123 with group_id
            // will sort courses by course_id in array order below. for this group_id
            $group_courses_args['post__in'] = array( 45, 23, 67, 12 ); // Replace with your course IDs in desired order
            $group_courses_args['orderby'] = 'post__in';
        break;
    
        case 321: // replace 321 with additional group_id
            // will sort courses by title in descending order for group_id
            $group_courses_args['orderby'] = 'title';
            $group_courses_args['order'] = 'DESC';
        break;
    }
    
    return $group_courses_args;
}, 10, 2 );