Сортировка пользовательских столбцов в пользовательской сетке WordPress

Я добавил пользовательский столбец в область сетки администратора WordPress, добавив эти коды в functions.php

function new_modify_user_table( $column ) {
$column['progress'] = 'Progress';
return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table',11 );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
switch ($column_name) {
case 'progress' :
$course_id=7238;
$course = learn_press_get_course( $course_id );$force             = true;
$num_of_decimal    = 0;
$current           = $course->evaluate_course_results( $user_id, $force );
$current           = absint( $current );

return  '<strong style="color: green">'.$current.'%</strong>';
break;
default:
}
return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 11, 3 );

Это показывает столбец в конце таблицы, как показано ниже

введите описание изображения здесь

Но это не позволяет мне сортировать.

Я добавил этот код, чтобы добавить ссылку сортировки в столбец заголовка таблицы

add_filter( 'manage_users_sortable_columns', 'my_sortable_cake_column' );
function my_sortable_cake_column( $columns ) {
$columns['progress'] = 'progress';

return $columns;
}

А также нашел, где вызвать сортировку

add_action( 'pre_user_query', 'my_pre_user_query', 1 );
function my_pre_user_query( $query ) {
global $wpdb, $current_screen;

// Only filter in the admin
if ( ! is_admin() )
return;

// Only filter on the users screen
if ( ! ( isset( $current_screen ) && 'users' == $current_screen->id ) )
return;

// Only filter if orderby is set to 'progress'
if ( isset( $query->query_vars ) && isset( $query->query_vars[ 'orderby' ] )
&& ( 'progress' == $query->query_vars[ 'orderby' ] ) ) {

// We need the order - default is ASC
$order = isset( $query->query_vars ) && isset( $query->query_vars[ 'order' ] ) && strcasecmp( $query->query_vars[ 'order' ], 'desc' ) == 0 ? 'DESC' : 'ASC';

//need to write code to apply to grid

}

}

Может кто-нибудь помочь мне написать код, который устанавливает сортировку в сетке

2

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector