• On my local MAMP install with wordpress, my site works fine. I am using wp_remote_post to take the values from the webpage form and send them to the php file that will insert the data into the database table in my wp database. This is called in the functions.php file for my theme.

    // create an array of the form fields to pass to the php file that will handle inserting 
        // new data into the database table
        $fields = array(
            'off_team_name' => $_POST['off_team_name'],
            'def_team_name' => $_POST['def_team_name'],
            'user_id' => $_POST['user_id']);
        // this calls the php file that will insert the data into your database table
        wp_remote_post( 'https://localhost/my_stuff/select.php', [
            'body' => $fields,
        ]);
Viewing 15 replies - 1 through 15 (of 15 total)
  • You should be checking the response any way, but what is the response from wp_remote_post

    e.g.

    $response = wp_remote_post( 'https://localhost/my_stuff/select.php', [
            'body' => $fields,
        ]);
    Thread Starter rockie12_us

    (@rockie12_us)

    I got past this wp_remote_post issue, the next line is

    wp_safe_redirect('http://mysite.com/teams/');

    this line does not seem to fire, it takes me to

    http://mysite.com

    • This reply was modified 1 year, 8 months ago by rockie12_us.
    • This reply was modified 1 year, 8 months ago by bcworkz. Reason: code format fixed
    Thread Starter rockie12_us

    (@rockie12_us)

    wp_safe_redirect response is 1

    Are you calling exit right after wp_safe_redirect

    Thread Starter rockie12_us

    (@rockie12_us)

    no

    Note: wp_safe_redirect() does not exit automatically, and should almost always be followed by a call to exit;:

    See https://developer.wordpress.org/reference/functions/wp_safe_redirect/

    As the questions would be endless – like what hook is this being fired in?

    • This reply was modified 1 year, 8 months ago by Alan Fuller.
    Thread Starter rockie12_us

    (@rockie12_us)

    I added

    exit;

    and it still doesn’t redirect to the page I want.

    Might help if you share your complete code – you can use a gist or other code sharing platform and link to it

    Thread Starter rockie12_us

    (@rockie12_us)

    Could godaddy websecurity on my site, be blocking the redirect?

    Try turning it off.

    Thread Starter rockie12_us

    (@rockie12_us)

    if (isset($_POST['selecteamsformbtn']) && wp_verify_nonce($_POST['tuokrow_etaerc'], 'select_teams')) {
        
        // create an array of the form fields to pass to the php file that will handle inserting 
        // new data into the database table
        $fields = array(
            'off_team_name' => $_POST['off_team_name'],
            'def_team_name' => $_POST['def_team_name'],
            'user_id' => $_POST['user_id']);
        // this calls the php file that will insert the data into your database table
        wp_remote_post( 'http://mysite.com/my_stuff/select.php', [
            'body' => $fields,
        ]);
        // after the data is inserted into the database you redirect them back to the workout form page
        wp_safe_redirect('https://mysite.com/my-teams/');
        exit;
        
    }
    
    }, 10);

    have you tried replacing with wp_redirect

    Thread Starter rockie12_us

    (@rockie12_us)

    Bingo!!!!
    Excellent!!!

    whats the difference?

    isnt safe better?

    Gold star for you sir.

    Safe will only go to the same domain ( or doamin you specifically nominate as safe )- I assume then that it is not going to the same domain

    Thread Starter rockie12_us

    (@rockie12_us)

    it is going to the same domain… odd safe didnt work.
    Thanks its working

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘wp_remote_post not working on my godaddy wp install’ is closed to new replies.