WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Pass href attributes of links to php variable using $_GET not working

[Resolved] Pass href attributes of links to php variable using $_GET not working

  • I’m trying to pass the href attributes of two links to php variable using $_GET.
    The code is quite simple, but it’s not working in wordpress:

    <a href="?link=time">Time</a>
    <a href="?link=function">Function</a>
    <?php
      $childof= 4;
      if(isset($_GET['link'])){
        $link=$_GET['link'];
        if ($link == 'function'){
             $childof= 9;
        }
        elseif ($link == 'time'){
            $childof= 4;
        }
    }
    ?>

    I’ve already installed WordPress Registry plugin, but $_GET is still not working at all. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I suggest you print out the $_GET array to see what is actually there:

    <a href="?link=time">Time</a>
    <a href="?link=function">Function</a>
    <?php
    print_r('<pre>$_GET:');print_r($_GET);print_r('</pre>');

    That was a good idea! It returns an array:

    $_GET:Array
    (
        [page_id] => 8/?link=function
    )

    I modified my code like this, it’s working now:

    <?php
      $childof= 4;
      if(isset($_GET[page_id])){
        $link=$_GET[page_id];
        if ($link == '8/?link=function'){
             $childof= 9;
        }
        elseif ($link == '8/?link=time'){
            $childof= 4;
        }
    }
    ?>

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Pass href attributes of links to php variable using $_GET not working’ is closed to new replies.
Skip to toolbar