我只想对delete函数执行批量操作。我在谷歌上研究了这么多例子,但还是做不到。如果有人能帮我解决这个问题,我将不胜感激。下面是我的代码。当选择并选择“在下拉列表中删除”并单击“应用”时,不会发生任何情况。
public function get_bulk_actions(){
$action = array(
"delete" =>"Delete"
);
return $action;
}
public function get_columns(){
$columns = array(
"cb"=>"<input type=\'checkbox\'/>",
"No"=>"No",
"Name"=>"Name",
"Email"=>"Email",
"Unique_Code"=>"Unique Code",
"Created_date"=>"Created Date"
);
return $columns;
}
public function column_cb($item){
return sprintf(\'<input type="checkbox" name="post[]" value="%s"/>\',$item[\'id\'] );
}
public function process_bulk_action() {
// If the delete bulk action is triggered
$action = $this->current_action();
if( \'delete\'===$action ) {
$delete_ids = esc_sql( $_POST[\'post\'] );
// loop over the array of record IDs and delete them
foreach ( $delete_ids as $did ) {
global $wpdb;
$wpdb->query($wpdb->prepare( "DELETE FROM mncplugin WHERE id=\'".$did."\'"));
}
wp_redirect( esc_url( add_query_arg() ) );
exit;
}
}