首页 > 解决方案 > 如何使用 ACF 过滤掉值?

问题描述

您好我正在尝试在 WordPress 上创建一个过滤器,它将使用 ACF(高级自定义字段)根据选中的复选框过滤掉值,我检查了我的代码并且值正在传递,它没有在控制台上显示任何错误,但结果不是过滤。对不起,如果这是一个微不足道的问题,我是这个插件的新手。

if(!isset($_GET['BtnSubmit'])){
                    $the_query = new WP_Query( array(
                                'posts_per_page'=>10,
                                'post_type'=>'accommodation',
                                'post_status' => 'publish',
                                'orderby' => 'date',
                                'order'   => 'ASC',
                                'paged' => get_query_var('paged') ? get_query_var('paged') : 1) 
                    );                      
                }
                //On Post back filter form Query
                if(isset($_GET['BtnSubmit'])){
                                    
                global $wpdb;

                $data_array = array (
                    'name-application' => $_GET['name-application'],
                    'destination-application' => $_GET['destination-application'],
                    'category-application' => $_GET['category-application'],
                    'amenities-application' => $_GET['amenities-application'],  
                    'tags-application' => $_GET['tags-application'],    
                );

                $_name = $data_array['name-application'];
                $_destination = $data_array['destination-application'];
                $_category = $data_array['category-application'];
                $_amenities = $data_array['amenities-application'];
                $_tags = $data_array['tags-application'];

$the_query = new WP_Query( array(
                    'posts_per_page'=> 10,
                    'post_type'=> 'accommodation',
                    'post_status' => 'publish',
                    'orderby' => 'date',
                    'order'   => 'ASC',
                    'tax_query' => array(
                        'relation' => 'AND',
                            array(
                                'taxonomy' => 'category',
                                'field' => 'term_id',
                                'terms' => $_category,
                                'include_children' => true,
                                'operator' => 'IN'
                            ),
                            array(
                                'taxonomy' => 'post_tag',
                                'field' => 'term_id',
                                'terms' => array($_tags),
                                'operator' => 'LIKE'
                            ),
                            'meta_query' => array(
                                'relation' => 'AND',
                                    array(
                                        'key' => 'destinations',
                                        'type' => 'NUMERIC',
                                        'value' => $_destination,
                                        'compare' => '='
                                    ),
                                    array(
                                        'key' => 'amenities',
                                        'type' => 'CHAR',
                                        'value' => serialize(array(implode(", ", $_amenities))),
                                        'compare' => '='
                                    )
                                ),
                            ),
                        'relation' => 'AND',
                        's' => $_name,
                        'paged' => get_query_var('paged') ? get_query_var('paged') : 1)
                    );                                      
                }

 <ul class="ks-cboxtags">
                            <li><input name="amenities-application[]" type="checkbox" id="checkboxTwo" value="Bar"  <?php  if( in_array ("Bar", $_GET['amenities-application'])) { echo "checked=\"checked\"";  }?>><label for="checkboxTwo">Bar</label></li>                               
                          </ul>

标签: phpwordpressadvanced-custom-fields

解决方案


推荐阅读