I’m working on a custom data table to display in the WordPress dashboard. The table populates from a database table I built in a plugin.
I’ve been using the provided WordPress Custom List Table example for most of my coding questions in this area, but the example doesn’t have anything for handling bulk actions. Here is the link for the documented example: http://wordpress.org/extend/plugins/custom-list-table-example/
For processing the bulk actions, the example only provides this:
function process_bulk_action() {
//Detect when a bulk action is being triggered...
if( 'delete'===$this->current_action() ) {
wp_die('Items deleted!');
}
}
I want to know how to pull the items selected for the action so I can delete them or edit their database entries accordingly.
Assuming you’re using the standard column_cb() function, the list table will pass the IDs of the selected rows in an array in $_GET, labeled as whatever you assigned to ‘singular’ in the list table’s constructor.
Here’s a typical column_cb():
For example, let’s say I have a list table that displays videos. The constructor would look like:
So, if you check three rows in the list table, select “Delete” from the bulk actions list, and hit apply, you could access the selected rows by using $_GET[‘video’].