php - 如何为 wp Job manager 制作自定义过滤器
问题描述
嗨,我希望有人可以帮助我,我正在使用 wp 作业管理器插件,并且我正在寻找如何根据我在属性字段(即游泳池、海滩访问)中创建的字段实现我自己的过滤器,因此任何添加了游泳池、海滩的属性访问将显示,如果可能的话,我希望能够多选这个代码是从添加薪水字段向正确方向迈出的一步,这可以修改为我正在寻找的规格,我真的很难找到解决方案,基本上它是为了属性站点能够在下拉列表中显示我自己的自定义字段
add_action( 'job_manager_job_filters_search_jobs_end', 'filter_by_disabled_access_field' );
function filter_by_disabled_access_field() {
?>
<div class="search_categories">
<label for="search_categories"><?php _e( 'disabled access', 'wp-job-manager' ); ?></label>
<select name="filter_by_disabled_access" class="job-manager-filter">
<option value=""><?php _e( 'Disabled Access', 'wp-job-manager' ); ?></option>
<option value="yes"><?php _e( 'Yes', 'wp-job-manager' ); ?></option>
<option value="no"><?php _e( 'No', 'wp-job-manager' ); ?></option>
</select>
</div>
<?php
}
/**
* This code gets your posted field and modifies the job search query
*/
add_filter( 'job_manager_get_listings', 'filter_by_disabled_access_field_query_args', 10, 2 );
function filter_by_disabled_access_field_query_args( $query_args, $args ) {
if ( isset( $_POST['form_data'] ) ) {
parse_str( $_POST['form_data'], $form_data );
// If this is set, we are filtering by salary
if ( ! empty( $form_data['filter_by_disabled_access'] ) ) {
$selected_range = sanitize_text_field( $form_data['filter_by_disabled_access'] );
switch ( $selected_range ) {
case 'yes' :
$query_args['meta_query'][] = array(
'key' => '_disabled_access',
'value' => 'yes',
'compare' => '>=',
'type' => 'TEXT'
);
break;
case 'no' :
$query_args['meta_query'][] = array(
'key' => '_disabled_access',
'value' => 'no',
'compare' => '=<',
'type' => 'TEXT'
);
break;
default :
$query_args['meta_query'][] = array(
'key' => '_disabled_access',
'value' => array_map( 'absint', explode( '-', $selected_range ) ),
'compare' => 'BETWEEN',
'type' => 'TEXT'
);
break;
}
add_filter( 'job_manager_get_listings_custom_filter', '__return_true' );
}
}
return $query_args;
}
到目前为止我有这个工作但是只有一个选项禁用访问我想添加更多来过滤掉这怎么可能
解决方案
推荐阅读
- c# - 切换到另一个表单时禁用 C# Winform 标签
- typescript - typescript 文件被识别为 MPEG-2 ts 文件
- php - 箭头和输入键在 datalist 上无法正常工作如何修复
- stripe-payments - 在本期结束时降级 Stripe 订阅?
- angular - Angular 8根据父类禁用按钮
- java - 在 reduce 操作中使用 StringBuilder(...) 作为标识值会产生不可预测的结果
- javascript - 如何使用javascript从字符串生成关键字
- php - LastModified http 标头上的 500 内部服务器错误(无效字符)
- android - Xposed 模块“提前三步”在 Android 7.0 上崩溃
- python - 循环多维numpy数组