• Resolved myjosephines

    (@myjosephines)


    I’m trying to create a php redirect that redirects to an url + epi with a member id.

    Not sure how to get these two together :/

    <?php $current_user_id = get_current_user_id(); echo $current_user_id; ?>

    and

    <?php
    wp_redirect('https://domain.com'); exit();
    ?>

    The end result would be https://domain.com/?=MEMBERID

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter myjosephines

    (@myjosephines)

    I got it to work (almost) and want to use this:

    <?php
    $loc = 'https://domain.com/?epi=' . $user_ID = get_current_user_id();
    header("Location: $loc");
    die(0);
    ?>

    However, it only works when used in index.php in the theme-folder, and not in a clean php-file. Because then it says: “Fatal error: Call to undefined function get_current_user_id() in C:\xampp\htdocs\domain\link\index.php on line 2”

    Thread Starter myjosephines

    (@myjosephines)

    Got it to work. I had to call wordpress functions in the beginning – like this:

    <?php
    if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__)); //getting current directory using magic constants __DIR__ is deprecated in php 5.3.+
    $path = explode('wp-content',__DIR__); //getting main web root path for including further files.
    include_once($path[0].'wp-load.php'); //for getting global variables like wpdb
    global $current_user;   
    
    $loc = 'https://domain.com/?epi=' . $user_ID = get_current_user_id();
    header("Location: $loc");
    die(0);
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect and fetch member id?’ is closed to new replies.