Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to query the custom post type by the three fields below. The two select fields and the one text field. The text field is the one that is not working currently.

What is wrong? How can I fix that?

        <form name="search" action="" method="get">

            <label for="city">City:</label>
            <select name="city" style="width:175px;" >
            <?php
            $cities = mo_baptist_get_meta('street_city');
            if ($cities) {
                foreach ($cities as $city) {
                    echo "<option value=\"" . $city . "\">" . $city . "</option>";
                }
            }
            ?>
            </select>
            <label for="association">Association:</label>
            <select name="association" style="width:175px;">
            <?php
            $associations = mo_baptist_get_meta('association');
            if ($associations) {
                foreach ($associations as $association) {
                    echo "<option value=\"" . $association . "\">" . $association . "</option>";
                }
            }
            ?>
            </select>

            <input type="text" name="zipcode" placeholder="Zip Code" value="<?php $zip_code = mo_baptist_get_meta('street_zip'); ?>"

            <input type="submit" value="search" />
        </form>
        <?php $az = range('a', 'z');


        ?>

      <table>
          <colgroup>
            <col width="300">
            <col width="200">
            <col />
            <col />
          </colgroup>

          <thead>
            <th><?php _e('Name'); ?></th>
            <th><?php _e('City'); ?></th>
            <th><?php _e('Phone'); ?></th>
            <th><?php _e('Website'); ?></th>
          </thead>

          <tbody>
            <?php $zip_code = $_GET['street_zip']; $cities = $_GET['city'];  $associations = $_GET['association']; 
            if ($cities  || $associations  || $zip_code) {
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args=array(
                'post_type'  =>  'church',
                'order'  => 'ASC',
                'orderby'  => 'title',
                'posts_per_page'  => 25,
                'paged'=>$paged,
                'meta_query'  =>  array(
                    array(
                        'value'  =>  $cities,
                    ),
                    array(
                        'value'  =>  $associations,
                    ), 
                    array(
                        'value'  =>  $zip_code,
                    )
                )
              );
              query_posts($args);
            } else {
             query_posts(array(
                'post_type'  =>  'church',
                'order'  => 'ASC',
                'orderby'  => 'title',
                'posts_per_page'  => 25,
                'paged'  =>  $paged
            )); } if (have_posts()): while (have_posts($paged)): the_post(); $church = get_post_custom($post->ID); ?>
              <tr>
                <td><a href="<?php the_permalink(); ?>" id="church-<?php the_ID(); ?>"><?php the_title(); ?></a></td>
                <td><?php echo $church['street_city'][0]; ?></td>
                <td><?php echo $church['phone'][0]; ?></td>
                <td><?php if (!empty($church['website_url'][0])): ?><a href="http://<?php echo $church['website_url'][0]; ?>"><?php _e('Homepage') ?></a><?php endif; ?></td>
              </tr>
            <?php endwhile; endif; ?>
          </tbody>
        </table>

        <div class="search-pagination">

          <?php kriesi_pagination(); ?>

        </div>

  </div>
share|improve this question
add comment

1 Answer

If what you are trying to do is pre-populate the text input, it looks to me like you need to echo the $zip_code variable you are creating:

<input type="text" name="zipcode" placeholder="Zip Code" value="<?php $zip_code = mo_baptist_get_meta('street_zip'); echo $zip_code ?>" />

other than that, I also noticed that the text input was not closed - I added that in the above example...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.