Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I access $_POST data after a page redirect?

I guess there is some way to tell WordPress to pass all $_POST data to the redirected address, like it does with $_GET data, using Rewrite Rules, but how?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Redirects are GET requests usually, and the browser doesn’t send the POST data for those. That’s not something WordPress can change.

You could create a session, or – better – process the POST data first, then redirect. In your plugin, you could do:

add_action( 'plugins_loaded', 'process_post_data', 0 );

function process_post_data()
{
    // Read raw POST data, not touched by WordPress
    $data = file_get_contents( 'php://input' );

    // then redirect
}
share|improve this answer
    
That's fine, where I can hook a function to get the $_POST data in Wordpress before redirect? –  Archedius Apr 30 '13 at 8:51
    
@Archedius See my update. –  toscho Apr 30 '13 at 8:57
    
That answers my question. It doesn't work with Rewrite Rules though, I have to analyze the URL without rewriting then redirect at Template Redirect, I think. –  Archedius Apr 30 '13 at 9:18
    
@Archedius Internal redirect (no URL change) are fine. Redirects for the browser (to a new URL) should come after POST data processing. –  toscho Apr 30 '13 at 9:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.