Попытка создать WP List Table для моего меню администратора, но таблица не отображается. Ниже приведен пример изображения, на что выводится изображение. 1-е изображение показывает отсутствие таблицы, а второе изображение, если я получаю какие-либо данные из запроса.
- Код таблицы списка WP: Здесь находится таблица списка wp
class Register_List extends WP_List_Table
{
public function __construct()
{
parent::__construct( [
//'singular' => __( 'Customer', 'sp' ), //singular name of the listed records
//'plural' => __( 'Customers', 'sp' ), //plural name of the listed records
'ajax' => false //should this table support ajax?
] );
}
public static function get_customers( $per_page = 5, $page_number = 1 )
{
global $wpdb;
$table_name = $wpdb->prefix . "pinesuit_register";
$sql = "SELECT * FROM {$table_name}";
if ( ! empty( $_REQUEST['orderby'] ) ) {
$sql .= ' ORDER BY ' . esc_sql( $_REQUEST['orderby'] );
$sql .= ! empty( $_REQUEST['order'] ) ? ' ' . esc_sql( $_REQUEST['order'] ) : ' ASC';
}
$sql .= " LIMIT $per_page";
$sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
return $result;
}
public function column_default( $item, $column_name )
{
switch ( $column_name ) {
case 'register_id':
case 'first_name':
case 'last_name':
case 'company':
case 'phone':
case 'email':
case 'membership_level':
case 'reward_points':
return $item[ $column_name ];
default:
return print_r( $item, true ); //Show the whole array for troubleshooting purposes
}
}
function get_columns()
{
$columns = [
'register_id' => 'Register ID',
'first_name' => 'First Name',
'last_name' => 'Last Name',
'company' => 'Last Name',
'phone' => 'Last Name',
'email' => 'Email',
'membership_level' => 'Membership Level',
'reward_points' => 'Reward Points'
];
return $columns;
}
public function get_sortable_columns()
{
$sortable_columns = array(
'register_id' => array( 'register_id', true ),
'first_name' => array( 'first_name', false )
);
return $sortable_columns;
}
public static function record_count()
{
global $wpdb;
$table_name = $wpdb->prefix . "pinesuit_register";
$sql = "SELECT COUNT(*) FROM {$table_name}";
return $wpdb->get_var( $sql );
}
public function prepare_items()
{
$this->_column_headers = $this->get_column_info();
/** Process bulk action */
// $this->process_bulk_action();
$per_page = $this->get_items_per_page( 'customers_per_page', 5 );
$current_page = $this->get_pagenum();
$total_items = self::record_count();
$this->set_pagination_args( [
'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $per_page //WE have to determine how many items to show on a page
] );
// print_r($this->items = self::get_customers( $per_page, $current_page ));
// die;
$this->items = self::get_customers( $per_page, $current_page );
}
}
Меню администратора: это меню администратора
public static function pinesuit_table(){
include trailingslashit(substr(dirname(__FILE__), 0, -9)) . 'inc/View/RegisterTable.php';
$myListTable = new Register_List();
echo '<div class="wrap"><h2>My List Table Test</h2>';
$myListTable->prepare_items();
$myListTable->display();
echo '</div>';
}
![enter image description here](https://i.stack.imgur.com/CUUDQ.png)