Support » Developing with WordPress » $_GET in WordPress

  • Resolved katybe

    (@katybe)


    Hi there,

    I build a Landing Page in WordPress for a Tell-A-Friend-campaign. This page should include sth. like “See, what <firstname> found:”. The first name placeholder should be dynamically replaced with a name given by the web address. For example, if I open the address domain.com/tellafriend?firstname=Melanie should print the text “See, what Melanie found:”.

    These are the solutions I tried, which didn’t work:
    <?php if(isset($_GET[‘firstname’])) echo strip_tags($_GET[‘firstname’]); ?>
    and
    <?php echo get_query_var(‘firstname’); ?>

    Is there any way to print out parameters?

    Thanks a lot for your help,

    Katy

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    $_GET[‘firstname’] should work, but if a redirect is involved, query strings like ?firstname=Melanie can sometimes get dropped. The query var attempt failed because firstname isn’t a registered query var AFAIK. Even if it is, there’s the same problem of query strings being dropped through a redirect.

    FWIW, I setup the scenario you’ve described on my own site, echoing out $_GET[‘firstname’] from a page template. It worked fine, but then my site doesn’t involve any redirects. Note that WP permalinks which do not end with a final slash will get a 302 redirect. However, for this particular redirect, query strings should be preserved.

    It’s also possible for other code to unset $_GET values, something like that could be at play. In summary, using $_GET values should work, but there can be reasons it doesn’t, but we don’t have enough information to speculate on what they might be.

    Thread Starter katybe

    (@katybe)

    Hello,

    thank you very much. I now found a solution. Had to register firstname.

    Best regards,

    Katy

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘$_GET in WordPress’ is closed to new replies.