Title: custom meta_query using a variable for the value
Last modified: August 20, 2016

---

# custom meta_query using a variable for the value

 *  [Eddie](https://wordpress.org/support/users/mseddie/)
 * (@mseddie)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/custom-meta_query-using-a-variable-for-the-value/)
 * I want to do a post query of post type ‘page’ and a custom meta field called ‘
   related_category’.
 * The query appears on the taxonomy page and what it’s supposed to do is load the
   content of a page that is related to the current term. The idea is that the related
   page acts as a description for the current term allowing the client to edit this
   content the same as they would a regular page.
 * Basically what I need to do is set the ‘value’ to be $thisTerm. Calling the value
   as a variable is the part that’s not working for me, if I set the value to a 
   number, it works just fine.
 * I’m hoping this is just a simple syntax error, that maybe there’s something different
   I should be doing in the array when calling a variable.
 *     ```
       <?php
                               $thisTerm = $term->term_id;
                           ?>
                       <div id="courses_content_column" class="span8">
                           <?php
                               query_posts(array('post_type'=>'page',
                                           'meta_query' => array(
                                                           array ('key' => 'related_category',
                                                                   'value' => $thisTerm
                                                                   ),
                                                               ),
                                                       ));
                           ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/custom-meta_query-using-a-variable-for-the-value/#post-3077390)
 * As far as I can see, your code is correct. To verify that it is, set $thisTerm
   to a number and see if it works.
 *     ```
       $thisTerm = 44; // Substitute your actual term_id
       ```
   
 * If that works, then more than likely $term->term_id is not returning what you
   think it should.

Viewing 1 replies (of 1 total)

The topic ‘custom meta_query using a variable for the value’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/custom-meta_query-using-a-variable-for-the-value/#post-3077390)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
