我想在wordpress中使用wp_list_table創建自定義表。我正在嘗試顯示ID,用戶名和用戶郵件。我已經創建了自定義表格作爲插件。我的問題是表已經創建,但我無法獲取數據。這是我的代碼。爲什麼有2個表格顯示。請幫助我如何使用wp_list_table將數據提取到自定義wordpress表中
<?php
/*
Plugin Name: Custom Tables
*/
?>
<?php
if(! class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
class My_List_Table extends WP_List_Table {
function getdata($user_id){
$args= array(
'user_id' =>'ID',
'role' =>'',
'orderby' =>'login',
'fields' => 'ID','user_login','user_email');
$data = get_users($args);
}
function get_columns(){
$columns = array(
'ID' => 'Case ID',
'user_login' => 'Patient Name',
'user_email' => 'Patient Email'
);
return $columns;
}
function prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$sortable = array();
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = $this->example_data;;
}
function column_default($item, $column_name) {
switch($column_name) {
case 'ID':
case 'user_login':
case 'user_email':
return $item[ $column_name ];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
}
// $myListTable = new My__List_Table();
function my_render_list_page(){
$myListTable = new My_List_Table();
echo '<div class="wrap"><h2>My List Table Test</h2>';
$myListTable->prepare_items();
$myListTable->display();
echo '</div>';
}
function my_add_menu_items(){
add_menu_page('My Plugin List Table', 'My List Table Example', 'activate_plugins', 'my_list_test', 'my_render_list_page');
}
add_action('admin_menu', 'my_add_menu_items');
}
?>
看看這個http://codingbin.com/display-custom-table-data-wordpress-admin/ – MKD