0

我有一个自定义帖子类型,其中包含一个复选框组“区域”,允许用户选择其服务涵盖的多个区域。

在前端,我有一个自定义搜索查询,允许用户按基本条件进行细化。

它工作正常,但我已经用复选框撞墙了。我尝试将数组输入到 meta_key 值(到目前为止尝试过内爆和爆炸),但我只能让它注册第一个检查项目。

我的 HTML 表单:

            <form id="searchform" method="post" action="">
                <fieldset>

                    <select name="service">
                        <option value="" <?php if(isset($_GET['service']) && $_GET['service'] == "") { echo 'selected'; } ?>>All</option>
                        <option value="3" <?php if(isset($_GET['service']) && $_GET['service'] == '3') { echo 'selected'; } ?>>Advocacy and Advice</option>
                        <option value="0">Alcohol and Drug Partnership</option>
                        <option value="0">Befriending</option>
                        <option value="0">Care &amp; Support at Home</option>
                        <option value="4" <?php if(isset($_GET['service']) && $_GET['service'] == '4') { echo 'selected'; } ?>>Care Homes</option>
                    </select>

                    <label class="radio" for="order-0">
                        <input name="order" id="order-0" value="ASC" type="radio" <?php if(isset($_GET['order']) && $_GET['order'] == 'DESC' || !$_GET['order']) { echo 'checked'; } ?>>
                        Ascending
                    </label>
                    <label class="radio" for="order-1">
                        <input name="order" id="order-1" value="DESC" type="radio" <?php if(isset($_GET['order']) && $_GET['order'] == 'DESC') { echo 'checked'; } ?>>
                        Descending
                    </label>

                    <h3>Areas covered</h3>
                    <div class="form-group">
                        <div class="col-md-4">
                            <div class="checkbox">
                                <label>
                                    <input name="areas[]" value="Ardrossan" type="checkbox" class="check">
                                    Ardrossan
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input name="areas[]" value="Largs" type="checkbox" class="check">
                                    Largs
                                </label>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>

                    <button type="submit" class="button green">Search</button>

                </fieldset>
            </form>

我的查询:

            $custom_taxterms = wp_get_object_terms( $post->ID, 'category', array('fields' => 'ids') );
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

            if($_POST['areas']) {
                $areas = $_POST['areas']; 
                $areas = implode(',',$areas);
            }
            else { $areas            = ''; }

            if($_GET['service']) {
                $service             = $_POST['service'];
            }
            else { $service          = 0; }

            if($_GET['order']) {
                $order               = $_POST['order'];
            }
            else { $order            = 'ASC'; }

            $args = array(
                'post_type'          => 'provider_listing',
                'cat'                => $service,
                'order'              => $order,
                'paged'              => $paged,
                'meta_query' => array(
                    array  (
                        'key'       => 'areas_covered',
                        'value'     => $areas,
                        'compare'   => 'LIKE'
                    )
                )
            );
            $providers = query_posts($args);

            if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 
            ......
4

0 回答 0