I have created a table in which i have delete link something like http://localhost/wptheme/wp-admin/admin.php?page=batch-op-settings&action=batch-delete&post_id=5 and i have added a code to delete the post
if ($action == 'batch-delete') {
require_once (plugin_dir_path( __FILE__ ).'views/single_batch_delete.php');
}
code in the required file is
if (isset($_GET['action']) == 'batch-delete') {
global $wpdb;
$delete_batch = $wpdb->delete( 'batch_number', array(
'id'=>$_GET['post_id']
) );
wp_redirect( $_SERVER['PHP_SELF'].'?page="batch-op-settings"', 302, 'Deleted' );
}
the data row is deleted but it is not redirecting to the all batches code all data i have used wp_redirect function i have also used header() function but it shows this error
Warning: Cannot modify header information - headers already sent
I want to know is there any better way to handle this issue or any solution with the current code .
admin_action_batch-delete
to handle your plugin action. From hooks like that, performing redirects shouldn't give you the "headers already sent" issue.admin_menu
-add_action( 'admin_action_batch-delete', function(){ // update/delete your data and then redirect } )
. Example