WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using url like «wp-login.php?action=register&role=patient» and «register_form» hook for add extra inputs form which depends on urls like this:


function add_extra_role_fields() {
if (isset($_GET['role'])) { $user_type = $_GET['role']; }

if (isset($user_type) && $user_type == "patient") [...] 
if (isset($user_type) && $user_type == "doctor") [...]

Problem: Wordpress redirects user after form validation with error to http://example.com/wp-login.php?action=register instead of http://example.com/wp-login.php?action=register&role=patient and all logic is broken.

Question: Can wordpress redirect user to previos url «?action=register&role=doctor» (not default «?action=register») ?

Solution: Thank you Jan Fabry :).

if ( isset($_REQUEST['role']) && ( ($_REQUEST['role'] == 'patient') OR ($_REQUEST['role'] == 'doctor') ) ) {

    add_filter( 'site_url', 'doctor_site_url', 10, 4 ); 

    function doctor_site_url( $url, $path, $scheme, $blog_id ) {
        if ( 'login_post' == $scheme ) {
            $url .= '&role='.$_REQUEST['role'];
        return $url;
share|improve this question
Why do you want to do this? – toscho May 27 '11 at 9:56
To do different registration pages for different user roles. – mvod May 28 '11 at 7:32
up vote 1 down vote accepted

If you want to keep this information in the $_GET, you will have to modify the form's action parameter URL. You can do this by hooking into site_url:

add_filter( 'site_url', 'wpse18418_site_url', 10, 4 );
function wpse18418_site_url( $url, $path, $scheme, $blog_id )
    if ( 'login_post' == $scheme ) {
        $url .= '&role=doctor'; // Or do this dynamically
    return $url;

But instead of always looking in the $_GET, it might be a solution to save the role field in a hidden field and check $_REQUEST instead - it will contain both $_GET and $_POST.

share|improve this answer

Your Answer


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.