Home › Forums › General Issues › Filtering through check boxes
Hello I’m trying to make a filter on WordPress that will filter out values based on checked checkboxes using ACF (Advanced Custom Fields), I inspected my code and the values are passing and it’s not showing any errors on console but the result is not filtering. Sorry if it’s a trivial issue I’m new to this plugin.
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)
);
}
<h6>SEARCH BY AMENITIES</h6>
<div class="filter-amenities">
<ul class="ks-cboxtags">
<li><input name="amenities-application[]" type="checkbox" id="checkboxOne" value="AC" <?php if( in_array("AC", $_GET['amenities-application'])) { echo "checked=\"checked\""; }?>><label for="checkboxOne">AC</label></li>
<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>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.