我在我的网站上使用WP Job Manager插件。在主页上我使用具有位置搜索输入的英雄搜索过滤器,这是当前的文本输入,但我想将其更改为带有设置选项的下拉列表。我已经能够使用所选选项轻松地将位置文本输入更改为下拉列表。 我点击搜索,下面的工作列表没有任何变化。
我试图改变源文件中输入的处理方式,但没有运气。当我在作业列表页面上输出“位置”输入的结果但它仍然作为空字段返回时。
我不知道是什么人试图完成所需的结果,所以任何帮助或输入都会受到赞赏。
以下代码是我的 part-job-filters.php 代码。
<?php
if ( ! class_exists( 'WP_Job_Manager' ) ) {
return;
}
$keywords = '';
$location = array();
$selected_category = array();
if ( ! empty( $_GET['search_keywords'] ) ) {
$keywords = sanitize_text_field( $_GET['search_keywords'] );
}
// Old Location input field
// if ( ! empty( $_GET['search_location'] ) ) {
// $location = sanitize_text_field( $_GET['search_location'] );
// }
if ( ! empty( $_GET['search_location'] ) ) {
$location = absint( $_GET['search_location'] );
}
if ( ! empty( $_GET['search_category'] ) ) {
if ( is_array( $_GET['search_category'] ) ) {
$selected_category = absint( reset( $_GET['search_category'] ) );
} else {
$selected_category = absint( $_GET['search_category'] );
}
$_GET['search_category'] = $selected_category;
}
if ( is_tax( 'job_listing_category' ) ) {
$term = get_queried_object();
$_GET['search_category'] = $selected_category = array( $term->term_id );
}
?>
<div class="form-filter">
<div class="form-filter-header">
<a href="#" class="form-filter-dismiss">×<span class="sr-only"> <?php esc_html_e( 'Dismiss filters', 'specialty' ); ?></span></a>
</div>
<?php
$has_categories = true;
$count = wp_count_terms( 'job_listing_category', array(
'hide_empty' => 1, // Hide empty, as they are not displayed by the dropdown anyway.
) );
if ( is_wp_error( $count ) || 0 === intval( $count ) || is_tax( 'job_listing_category' ) ) {
$has_categories = false;
}
$col_classes = array(
'keywords' => 'col-lg-3 col-xs-12',
'location' => 'col-lg-3 col-xs-12',
'category' => 'col-lg-3 col-xs-12',
'button' => 'col-lg-3 col-xs-12',
);
if ( ! get_option( 'job_manager_enable_categories' ) || ! $has_categories ) {
$col_classes = array(
'keywords' => 'col-lg-4 col-xs-12',
'location' => 'col-lg-4 col-xs-12',
'category' => '',
'button' => 'col-lg-3 push-lg-1 col-xs-12',
);
}
?>
<div class="container">
<div class="row">
<div class="<?php echo esc_attr( $col_classes['keywords'] ); ?>">
<label for="job-keywords" class="sr-only"><?php esc_html_e( 'Job Keywords', 'specialty' ); ?></label>
<input type="text" id="job-keywords" name="search_keywords" placeholder="<?php esc_attr_e( 'Keywords', 'specialty' ); ?>" value="<?php echo esc_attr( $keywords ); ?>">
</div>
<div class="<?php echo esc_attr( $col_classes['location'] ); ?>">
<label for="job-location" class="sr-only"><?php esc_html_e( 'Job Location', 'specialty' ); ?></label>
<div class="ci-select">
<select name="search_location" id="job-location" data-no_results_text="No results match" data-multiple_text="Select Some Options">
<option value="0">Select a location</option>
<option value="Eastern Cape">Eastern Cape</option>
<option value="Free State">Free State</option>
<option value="Gauteng">Gauteng</option>
<option value="kwazulu natal">kwazulu natal</option>
<option value="Limpopo">Limpopo</option>
<option value="Mpumalanga">Mpumalanga</option>
<option value="North West">North West</option>
<option value="Northern Cape">Northern Cape</option>
<option value="Western Cape">Western Cape</option>
<option value="Africa">Africa</option>
<option value="International">International</option>
<option value="All locations">All locations</option>
</select>
</div>
</div>
<?php if ( get_option( 'job_manager_enable_categories' ) && $has_categories ) : ?>
<div class="<?php echo esc_attr( $col_classes['category'] ); ?>">
<label for="job-category" class="sr-only"><?php esc_html_e( 'Job Category', 'specialty' ); ?></label>
<div class="ci-select">
<?php
$multiple = get_option( 'job_manager_enable_default_category_multiselect' );
job_manager_dropdown_categories( array(
'taxonomy' => 'job_listing_category',
'hierarchical' => 1,
'show_option_all' => $multiple ? false : esc_html__( 'Any category', 'specialty' ),
'name' => 'search_category',
'orderby' => 'name',
'selected' => $selected_category,
'multiple' => $multiple,
) );
?>
</div>
</div>
<?php endif; ?>
<div class="<?php echo esc_attr( $col_classes['button'] ); ?>">
<button class="btn btn-block btn-jobs-filter" type="submit"><?php esc_html_e( 'Search', 'specialty' ); ?></button>
</div>
</div>
</div>
</div>
我可能会以错误的方式接近这个,如果是这样,请有人建议正确的方法是接近这个。
答案 0 :(得分:0)
将select元素中的id,id =“job-location”替换为id =“search_location”。