Title: Custom form value
Last modified: August 20, 2016

---

# Custom form value

 *  Resolved [Matthew](https://wordpress.org/support/users/mattycat/)
 * (@mattycat)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/custom-form-value/)
 * Hey guys,
 * I was wondering if it was possible to add a value to query_posts? I have a simple
   form on my website (www.bayofplenty.info) that has a select box to select the
   number of bedrooms a property has (which is a custom field) and I’m trying to
   add it to a results page query with the variable $bedrooms. The form is working
   fine because I can echo the results, but the query isn’t picking it up.
    The 
   query code I’m using is:
 *     ```
       <?php $bedrooms = $_POST['bedrooms']; ?>
         <?php $key = '_ct_selectbox_4e4f46f4788f8' ?>
         <?php query_posts('post_type=property&meta_key=$key&meta_value=$bedrooms&posts_per_page=10&orderby=ASC'); ?>
         <?php if (have_posts()) : ?>
         <?php while (have_posts()) : the_post(); ?>
         <?php the_title(); ?>
         <?php the_content(); ?>
         <?php endwhile; ?>
         <?php else: ?>
         Sorry, no results were found for your search.
         <?php endif; ?>
       ```
   

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/custom-form-value/#post-2255579)
 * You must use double quotes around the query string in order to interpolate variable
   values:
 *     ```
       <?php query_posts("post_type=property&meta_key=$key&meta_value=$bedrooms&posts_per_page=10&orderby=ASC"); ?>
       ```
   
 *  Thread Starter [Matthew](https://wordpress.org/support/users/mattycat/)
 * (@mattycat)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/custom-form-value/#post-2255626)
 * Cool, thanks. All works fine now! 😀

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

The topic ‘Custom form value’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [variables](https://wordpress.org/support/topic-tag/variables/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Matthew](https://wordpress.org/support/users/mattycat/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/custom-form-value/#post-2255626)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
