• trying to get this to work

    I need to be able to pass a custom variable to all the links as the visitor moves through the site ?rid=”a user id”

    That way you can share your link wordpresssite.com/?rid=2 and people check it out and want to join you can give them a signup link with member.wordpresssite.com/?rid=2

    I added 2 functions to the function.php

    `function add_query_vars_filter( $vars ){
    $vars[] = “rid”;
    return $vars;
    }
    add_filter( ‘query_vars’, ‘add_query_vars_filter’ );`

    and

    `function pass_rid () {
    if( !is_admin() && isset($_GET[‘rid’]) )
    {
    $rid = $_GET[‘rid’];
    $location = “http://”.$_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’];
    $location .= “?rid=”.$rid;

    echo $location;
    wp_redirect( $location );

    }
    }
    add_action(‘template_redirect’, ‘pass_rid’);`

    I end up with endless loops

    The echo is just to see if it is grabbing the variable

The topic ‘how do I add custom variable?’ is closed to new replies.