WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pass href attributes of links to php variable using $_GET not working (3 posts)

  1. Chuchy
    Member
    Posted 2 months ago #

    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!

  2. vtxyzzy
    Member
    Posted 2 months ago #

    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>');
  3. Chuchy
    Member
    Posted 2 months ago #

    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!

Reply

You must log in to post.

About this Topic