• Mike

    (@maltesesolutions)


    In my plugin, I am getting an error with wp_redirect.

    Here is my code:

    public function update($year, $edit_id, $column1, $column2) {
    
    		global $wpdb;
    
    		$table_name = $wpdb->prefix . 'tableName_'.$year;
    
    		$Column1 = intval($column1);
    
    		$Column2 = intval($column2);
    
    		$NewTotal = ($Column1 + $Column2);
    
    		$wpdb->update($table_name, array('Column1' => $Column1, 'Column2' => $Column2, 'Column3' => $NewTotal), array('month_id' => $edit_id));
    
    		wp_redirect(get_option('siteurl').'/wp-admin/admin.php?page=my-plugin');
    
    		exit();
    
    	}

    I know that the code is working until I get to wp_redirect.

    I get the following error

    Warning: Cannot modify header information – headers already sent by (output started at /home/…/public_html/wp-admin/includes/template.php:1953) in /home/…/public_html/wp-includes/pluggable.php on line 1171

    Any help would be greatly appreciated

Viewing 2 replies - 1 through 2 (of 2 total)
  • Anytime you are attempting to redirect using the wp_redirect, or the php header:location, you can only perform this action if you have not written anything to the header at all. This error is a pretty standard error and is caused by the fact that you have already written information in your header.

    The idea here is that you have to redirect your page before anything at all is written to the header. You may want to take a look at this information on Stack Overflow to get you started.

    https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php

    Hi,

    If I understand this correctly, you want to redirect to your plugin’s page after an update?

    Based on your error, it looks like that there could be white space form the top or bottom of you your plugin, as mentioned here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Having a problem with wp_redirect in my plugin’ is closed to new replies.