class Custom_List_Table extends WP_List_Table {
public function __construct() {
parent::__construct([
'singular' => 'item', // Used for nonces
'plural' => 'items', // Used for CSS classes
'ajax' => false
]);
}
// Fetch data (example)
public function prepare_items() {
$data = $this->fetch_data(); // Your query logic
$this->items = $data;
$this->set_pagination_args([
'total_items' => count($data),
'per_page' => 20
]);
}
// Define columns
public function get_columns() {
return [
'cb' => '<input type="checkbox">',
'title' => 'Title',
'date' => 'Date'
];
}
// Render "Title" column
public function column_title($item) {
return sprintf('<a href="%s">%s</a>', $item['url'], $item['title']);
}
}
Advanced Features
Bulk Actions:
public function get_bulk_actions() {
return ['delete' => 'Delete'];
}
public function process_bulk_action() {
if ('delete' === $this->current_action()) {
// Handle bulk delete
}
}
Search Box:
public function search_box($text, $input_id) {
parent::search_box('Search Items', 'search_id');
}