So, I found the problem.
First of all, I was not selecting the right ID’s on my checkbox or buttons, so I changed to code to do so:
function column_name($item){
$item_json = json_decode(json_encode($item), true);
$actions = array(
'edit' => sprintf('<a href="https://wordpress.stackexchange.com/questions/265648/?page=%s&action=%s&id=%s">Edit</a>', $_REQUEST['page'], 'edit', $item_json['id']),
'delete' => sprintf('<a href="https://wordpress.stackexchange.com/questions/265648/?page=%s&action=%s&id=%s">Delete</a>', $_REQUEST['page'], 'delete', $item_json['id']),
);
return '<em>' . sprintf('%s %s', $item_json['name'], $this->row_actions($actions)) . '</em>';
}
Notice here that I have $items
now who will get all the data needed. I will do an JSON decode and encode to turn it into an array and after that I can call the JSON array id
or name
in the sprinttf()
where I need it.
Same for the checkboxes (without the JSON):
function column_cb($item) {
return sprintf(
'<input type="checkbox" name="id[]" value="%s" />',
$item->id
);
}
After that i added this to my case ‘delete’ :
case 'delete':
global $wpdb;
$table_name = $wpdb->prefix . 'designitcountries';
if ('delete' === $this->current_action()) {
$ids = isset($_REQUEST['id']) ? $_REQUEST['id'] : array();
if (is_array($ids)) $ids = implode(',', $ids);
if (!empty($ids)) {
$wpdb->query("DELETE FROM $table_name WHERE id IN($ids)");
}
}
wp_die( 'You have deleted this succesfully' );
break;
Now I have a working method to delete from the buttons and from the checkboxes.