基于文本输入的定制邮政类型查询

时间:2012-10-04 作者:Matt Pritchett

我想通过以下三个字段查询自定义帖子类型。两个选择字段和一个文本字段。文本字段是当前不起作用的字段。

怎么了?我怎样才能解决这个问题?

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

1 个回复
SO网友:dzogchen

如果您试图预填充文本输入,那么在我看来,您需要回显正在创建的$zip\\u代码变量:

<input type="text" name="zipcode" placeholder="Zip Code" value="<?php $zip_code = mo_baptist_get_meta(\'street_zip\'); echo $zip_code ?>" />
除此之外,我还注意到文本输入没有关闭-我在上面的示例中添加了。。。

结束

相关推荐