Get Referrer ID


Staff member
Im trying to modify this wordpress plugin of mine to track the name of who reffered the current logged user.

So far I managed to build the code below, but i'm very new with any kind of coding and I would be very thankfull if I get some help.

The idea is to get the "parent_user_id" (the referrer id) from the current user, them use this ID to get the login_ID.

<strong>Actualy this code is outputting this: "Referred by: Array"</strong>

function wpmlm_display_referrer() {
    global $wpdb, $user_ID, $current_user;
    if(isset($_GET['current_user_id']) &amp;&amp; !empty($_GET['current_user_id'])) {
        $current_user_id = $_GET['current_user_id'];
    } else {
        $current_user_id = $current_user-&gt;ID;

    # Logged in user
    if ( is_user_logged_in() == true ) {            

        $get_id = "SELECT parent_user_id FROM mlm WHERE user_id=%d".$current_user_id;
        $get_name = "SELECT login_id FROM mlm WHERE user_id=%d".$get_id;
        $ref = $wpdb-&gt;get_results($get_name);

        return 'Referred by: '.$ref;    

Thank you for any help you can provide in this situation.