Redirect to Page after Post Submit

You can’t. If you wish to redirect a user by PHP, you should set the response header. If you output any data, you will not be able to, and you will get a Header already sent error.

Look at this line:

wp_redirect( home_url('/?page_id=7') ); 
exit;

echo $result;
die();

When you use exit ( which is the same as die() ), you are terminating the script. The next lines will never be executed. So my suggestion is to either use AJAX to redirect, or change your form to something like this:

<form action="<?php echo admin_url ( 'admin-ajax.php' ); ?>">

    <!-- This is to set the action of your query args -->
    <input type="hidden" name="action" value="search"/>

    <!-- Rest of your form here -->

</form>

Then, remove the line after exit and also the AJAX script, if you aren’t relying on it for something important.

Leave a Comment