0

I have a wp_list_table that is functioning, ie - I can add records to the table, delete individual records, edit individual records, and delete bulk records. Only one issue. After I do a bulk delete the records deleted still show in the list. When I refresh the page, they are gone. What is confusing is that the count of records is correct. Any help will be appreciated. Here is my process_bulk_action function. Thanks,

    public function process_bulk_action() {
    global $wpdb;
    $table = $wpdb->prefix . 'golf_pool_teams';
   // security check!
    if ( isset( $_POST['_wpnonce'] ) && ! empty( $_POST['_wpnonce'] ) ) {
        $nonce  = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
        $action = 'bulk-' . $this->_args['plural'];
        if ( ! wp_verify_nonce( $nonce, $action ) )
            wp_die( 'Nope! Security check failed!' );
    }
    $action = $this->current_action();

    if ( isset($_POST['team_id'])) {
        $row_id = $_POST['team_id'];
        switch ( $action ) {
            case 'delete':
                foreach($row_id as &$row){
                    $wpdb->delete($table, array('ID' =>$row));
                }
              break;

            default:
                // do nothing
                return;
                break;
            }
        return;
    } 
}            
1
  • I was mistaken saying that the count showed the updated row count. It shows the number of rows in the list which does not change until I refresh the page (using browser refresh). I'm really struggling with this. I can find any examples of how to handle bulk deletes. Most just say "delete here". I'm out of ideas. Thanks
    – Bud
    Dec 21, 2020 at 0:27

1 Answer 1

0

All that I had to do was to move the $this->process_bulk_action(); line of code to the beginning of the prepare_items() function.

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.