0

I only want to do bulk action on delete function. I have research so many example on google but still cant make it. Will be so much appreciate if someone be able to help me out on this. Below are my codes. When Select and choose delete on drop down and click apply, nothing is happen.

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;
                    }
}
3
  • Which view exactly is this - a normal admin view that you've hooked into and extended (can you show us the add_action calls?), or a new view specific to your plugin and tables?
    – Rup
    Commented Jan 11, 2021 at 11:04
  • hi @Rup , ya, it is my plugin view. Commented Jan 12, 2021 at 1:01
  • can you pls help me on this? Commented Jan 12, 2021 at 4:51

1 Answer 1

0

Wrap your ->display() into a form tag, something like below;

<form id="list-table-form" method="post">
 <?php $exampleListTable->display(); ?>
</form>

It won't work without form tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.