php - 如何使用 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>
解决方案
推荐阅读
- java - 为什么我的回文检查器总是评估为真?我尝试调试,结果不一样
- spring-boot - Spring boot logbcak to file在tomcat上不起作用
- amazon-web-services - 如何从 EC2 连接到本地 VPN?
- sycl - 为什么默认情况下每个 SYCL 设备都在单独的上下文中?
- mongodb - MongoDb 聚合 $count 显示 0
- javascript - 如何维护多个数组索引列表,其值由输出结果数组的函数使用?
- r - 具有多个组的 Power BI 相关性度量
- webview - Flutter WebView 插件无法播放某些 YouTube 视频
- java - 为什么将局部变量和易失性都用于 DCL(如 Sonar 工具所建议的那样)?
- c++ - 如何在 C++ 代码中使用 gnu diff 的输出?