Title: $_GET in a function in functions.php
Last modified: August 20, 2016

---

# $_GET in a function in functions.php

 *  [sam_beckett](https://wordpress.org/support/users/sam_beckett/)
 * (@sam_beckett)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/_get-in-a-function-in-functionsphp/)
 * Hello,
 * In my comments.php I inserted a form :
 *     ```
       <form name="myForm" action="" method="GET" style="float:right" >
       		<SELECT NAME="format">
       <OPTION>Test 1
       <OPTION>Test 2
       </SELECT>
       		<SELECT NAME="ordre">
       <OPTION>Example 1
       <OPTION>Example 2
       </SELECT>
       	<input type="submit" name="submit" value="Trier">
           		</form>
       ```
   
 * I want to store the selected value in a cookie, so I added this function to my
   functions.php :
 * <?php
    function set_navi_cookie() { $sc_ordre = $_REQUEST[‘ordre’]; setcookie(‘
   naviga’,$sc_ordre,time()+60, COOKIEPATH, COOKIE_DOMAIN, false); } add_action(‘
   init’, ‘set_navi_cookie’); ?>
 * but **$sc_ordre is null**. I tried $_REQUEST[‘ordre’]; but it’s always null.
 * What I did wrong ?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [Peter Wilson](https://wordpress.org/support/users/peterwilsoncc/)
 * (@peterwilsoncc)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/_get-in-a-function-in-functionsphp/#post-2450348)
 * Does it work if you change the select to:
 *     ```
       <SELECT NAME="ordre">
       <OPTION value="Example 1">Example 1</OPTION>
       <OPTION value="Example 1">Example 2</OPTION>
       </SELECT>
       ?>
       ```
   
 *  Thread Starter [sam_beckett](https://wordpress.org/support/users/sam_beckett/)
 * (@sam_beckett)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/_get-in-a-function-in-functionsphp/#post-2450509)
 * Thanks for your help, but no, it doesn’t work. I think that </option> is not 
   needed in this example.
 * I can catch the passing variables in single.php for exemple but not in functions.
   php where I need it.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/_get-in-a-function-in-functionsphp/#post-2450623)
 * It’s invalid not to have closing tags for options, so yes they are required if
   you want to write valid code.
 * `$sc_ordre` will be null outside the function because it only has scope inside
   the function.
 * About variable scope
    [http://php.net/manual/en/language.variables.scope.php](http://php.net/manual/en/language.variables.scope.php)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘$_GET in a function in functions.php’ is closed to new replies.

## Tags

 * [$_get](https://wordpress.org/support/topic-tag/_get/)
 * [$_REQUEST](https://wordpress.org/support/topic-tag/_request/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [setcookie](https://wordpress.org/support/topic-tag/setcookie/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 3 replies
 * 3 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/_get-in-a-function-in-functionsphp/#post-2450623)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
