Title: simple syntax issue of hardcoded value vs GET variable
Last modified: August 20, 2016

---

# simple syntax issue of hardcoded value vs GET variable

 *  Resolved [phpchick](https://wordpress.org/support/users/phpchick/)
 * (@phpchick)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/)
 * When I hardcode the value in, like I’ve done below. “Healthcare”, “Technology”,
   etc. My posts show up. However, this needs to be dynamically done via the URL
   GET Variable.
 *     ```
       $args = array(
       	'post_type' => 'earnings', // use to be stock
       	'posts_per_page' => 1,
       	'offset' => $_GET['offset'],
       		'meta_query' => array(
                               array(
       			'key' => 'sector',
       			'value' => 'Healthcare'
       			))
       );
       ```
   
 * However, when I do this.
 *     ```
       $args = array(
       	'post_type' => 'earnings', // use to be stock
       	'posts_per_page' => 1,
       	'offset' => $_GET['offset'],
       	'meta_query' => array(
                   array(
       			'key' => 'sector',
       			'value' => $_GET['sector'],
       			'compare' => '='
       			))
       );
       ```
   
 * The code busts and I do not get any results. I’ve tried setting
 * $_GET[‘sector’] to a variable first, and then doing
    `'value' => $variable` but
   that didn’t work either, and I have echoed that variable out to the screen and
   it indeed is “Healthcare”.
 * I’m not sure what I’m doing wrong, could anyone lend a helping hand?

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

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178786)
 * Try var_dumping $_GET and paste here (if it isn’t too long) the returned code.
 *  Thread Starter [phpchick](https://wordpress.org/support/users/phpchick/)
 * (@phpchick)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178789)
 * I did
 * `var_dump($_GET['sector']);`
 * and out went
 * string(10) “Financials”
 *  Thread Starter [phpchick](https://wordpress.org/support/users/phpchick/)
 * (@phpchick)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178793)
 * And here is %_GET by itself
 * array(5) {
    [“category”]=> string(5) “beats” [“date”]=> string(1) “4” [“sector”]
   => string(10) “Financials” [“expected_deviation”]=> string(8) “Moderate” [“expected_outlook”]
   => string(7) “Neutral” }
 *  Thread Starter [phpchick](https://wordpress.org/support/users/phpchick/)
 * (@phpchick)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178820)
 * Could this be an issue with the database?
 * I feel like the above should work
 * typing in the string works, but the identical string given through a variable
   doesn’t. The var_dump suggests that they are identical from what I can see. Anyone
   have any insight?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178826)
 * You need to first register your new variable before WordPress will recognise &
   use it. See [this Codex section](http://codex.wordpress.org/Custom_Queries#Custom_Archives).
 *  Thread Starter [phpchick](https://wordpress.org/support/users/phpchick/)
 * (@phpchick)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178845)
 * Just want to follow up so others can use the code if they need help.
 * I was able to fix the code thanks to esmi and here it is
 *     ```
       add_filter('query_vars', 'geturlvar' );
       function geturlvar( $qvars )
       {
         $qvars[] = 'sector';
         return $qvars;
       }
   
       $args = array(
       	'post_type' => 'earnings', // use to be stock
       	'posts_per_page' => 3,
       	'offset' => $_GET['offset'],
       	'meta_query' => array(
                   array(
       			'key' => 'sector',
       			'value' => $_GET['sector']
       			))
       );
       ```
   
 * Thank you so much esmi! <3
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178851)
 * Glad I could help 🙂

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

The topic ‘simple syntax issue of hardcoded value vs GET variable’ is closed to 
new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/simple-syntax-issue-of-hardcoded-value-vs-get-variable/#post-3178851)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
