• Resolved Matthew

    (@mattycat)


    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)
  • 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

    (@mattycat)

    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.