WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pass custom var in url (5 posts)

  1. seej
    Member
    Posted 6 years ago #

    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.

  2. seej
    Member
    Posted 6 years ago #

    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.

  3. whooami
    Member
    Posted 6 years ago #

    $wh = $_GET['wh'];

    beyond it being completely insecure?

  4. systematic
    Member
    Posted 5 years ago #

    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:
    http://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

  5. systematic
    Member
    Posted 5 years ago #

    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'

Topic Closed

This topic has been closed to new replies.

About this Topic