I am trying to use wp_list table to display my data in the plugin however its showing no data i am using the following. There is def test data is their any php editor that lest u debug like visual studio btw.
class TT_Example_List_Table extends WP_List_Table {
function __construct(){
global $status, $page;
//Set parent defaults
parent::__construct( array(
'singular' => 'realtyna', //singular name of the listed records
'plural' => 'realtyna', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );
}
function prepare_items() {
global $wpdb; //This is used only if making any database queries
$per_page = 5;
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$columns = $this->get_columns();
$data = $wpdb->get_results("SELECT * FROM realtyna");
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
$current_page = $this->get_pagenum();
$this->items = $data;
/**
* REQUIRED. We also have to register our pagination options & calculations.
*/
$this->set_pagination_args( array(
'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
'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
) );
}
function column_default($item, $column_name){
switch($column_name){
case 'name':
case 'phone':
return $item[$column_name];
default:
return print_r($item,true); //Show the whole array for troubleshooting purposes
}
}
function get_columns(){
$columns = array(
'name' => 'name',
'email' => 'email',
'phone' => 'phone'
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'name' => array('name',false), //true means it's already sorted
'email' => array('email',false),
'phone' => array('phone',false)
);
return $sortable_columns;
}
}
Aucun commentaire:
Enregistrer un commentaire