• Resolved seej

    (@seej)


    I’ve read lots of the threads for passing variables…so feel like I’ve tried a lot of different methods. But. Basically, I’m trying to pass a variable to an iframe that loads single.php, for displaying individual posts.

    In category-5.php I have:
    <a href="?p=<?php the_ID(); ?>?wh=1">link to post</a>

    In single.php I have:

    $wh = $_GET['wh'];
    echo "wh=" . $wh;

    Doesn’t work though. What am I doing wrong here? Any help greatly appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter seej

    (@seej)

    Ok. Anyone see what I did wrong in the code above? I just found it. ? should be an &. Works now.

    For future reference, it looks like this is about the simplest way I can think of to pass a variable to a page. Other form post/get or session based methods seem to be more complex.

    $wh = $_GET[‘wh’];

    beyond it being completely insecure?

    My objective is to show content of external database on a wordpress page.

    I have created a page template that includes php and an sql query that will query a non wordpress database on the fly. I wish to control the ouput of this page by getting a variable from the url.

    For example a url linking to this page may look like this:
    https://myblog.com?merchant=xyz

    I would then like to grab the “merchant” variable and insert into the sql code on the page template.

    I have tried

    WHERE merchant = ‘<?php echo $_GET[“$merchant”]; ?>’

    without success

    Are there any suggestions?

    Many thanks in advance

    In case it helps anyone else like me with little coding knowledge I achieved my objective by defining the variable using
    $q = (isset($_GET[“q”])

    where q is the merchant defined in the url

    The sql simply included the command WHERE merchant = ‘$q’

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pass custom var in url’ is closed to new replies.