Support » Fixing WordPress » How to access http GET parameters

  • Hi

    I want to pass a GET parameter in the URL, eg. http://www.mywebsite.com/?parameter=myParameter and then access it on the page, how do I do that?

    PHP is disabled, I think, otherwise I’d echo $_GET[‘parameter’], but I presume WordPress provides a method to reach it, but I can’t find it.

    I’m going to send that info back through a form processor in the template, so I’m all sorted barring wondering how to access the GET.

    All help appreciated 🙂

    Cheers
    J

Viewing 5 replies - 1 through 5 (of 5 total)
  • I am a little confused. WP requires PHP, so it can’t be disabled or WP would not run. The echo $_GET should work.

    Thanks. OK .. WordPress is the thing I’m unfamiliar with, so here’s what I’m doing:

    Editing a page in HTML mode, I’m inserting
    <p><?php echo “Hello “.$_GET[‘a’]; ?></p>

    That saves OK and doesn’t rip out the PHP bit, then I run the page, and what’s output is:

    <p><?php echo “Hello “.$_GET[‘a’]; ?></p>

    In other words, it’s not being interpreted.

    I know I can put PHP in the template, but I need it here in the page so I can pass these parameters in a hidden form field.

    Cheers
    J

    OK, WP does not execute PHP inside posts. It is dangerous to do so because a poster can hack your site using that.

    But, if you really need it, check out the Exec PHP plugin.

    Does WP provide another way to use the $_GET data within a post? Is there, for instance, a WP variable I can use that provides it?

    Or let me ask: if you wanted to pass a variable to a WordPress page, how would you do it? Eg. let’s say you wanted a WordPress page to display a photograph, but wanted to pass the filename? (Actually, I’ve done that with code in the template, but if you needed it in the body).

    Or is it just that I need to put all my form into the header to solve my problem?

    J

    If you want to show a different picture on different pages, you can use a Custom Field to contain the URL of the picture.

    AFAIK, there is no built-in way to access the $_GET data inside of the post content. You should be able to add a shortcode to display the picture. For details, see the links below:

    Codex: Shortcode API

    Smashing Magazine: Mastering WordPress Shortcodes. See especially example 6. Get the Last Image Attached to a Post.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to access http GET parameters’ is closed to new replies.