Passing values through url for checkbox fields with same name to get?
Look to this images For example chose Ajna then select Residential and Hotel Apartment after click Search Properties = I need to show items that have these categories
ul id=actionslist class=dropdown-menu filter_menu role=menu aria-labelledby=adv_actions
li role=presentation data-value=allProject Types/li
?php
// Get Projects
$tab_terms_types = array();
$terms_types = get_terms( 'property_action_category', array(
'hide_empty' = false,
) );
foreach( $terms_types as $single_term_type ){
$args_types = array(
'post_type' = 'estate_property',
'author' = -1,
'posts_per_page' = -1,
'post_status' = 'publish',
'meta_key' = 'prop_featured',
'orderby' = 'meta_value',
'order' = 'DESC',
'tax_query' = array(
array(
'taxonomy' = 'property_action_category',
'field' = 'term_id',
'terms' = $single_term_type-term_id,
),
),
'fields' = 'ids'
);
$all_posts_types = get_posts( $args_types );
if( count( $all_posts_types ) 0 )
$tab_terms_types[ $single_term_type-term_id ] = array( 'name' = $single_term_type-name, 'slug' = $single_term_type-slug, 'count' = count( $all_posts ) );
}
foreach($tab_terms_types as $term){
?
div
input type=checkbox id=?php echo $term['slug']; ? class=types-input
name=filter_search_action[] value=?php echo $term['slug']; ?
data-value=?php echo $term['slug']; ?
label for=?php echo $term['slug']; ??php echo $term['name']; ?/label
/div
? } ?
/ul
jQuery Ajax
const typesArray = [];
$(.types-input).click(function(event){
if($(this).prop(checked) == true){
typesArray.push(jQuery(event.target).attr('data-value'));
console.log(typesArray);
}
})
$(.types-input).change(function(){
const ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
const nonce = jQuery('#wpestate_tab_stats').val();
$.ajax({
method: GET,
url: ajaxurl,
data: {
'action': 'wpestate_load_types',
'type_slug': typesArray,
'security': nonce
},
success: function(data){
$(.res-type).html(data);
console.log(data);
console.log(typesArray);
}
})
})
functions.php
add_action( 'wp_ajax_wpestate_load_types', 'wpestate_load_types' );
add_action( 'wp_ajax_nopriv_wpestate_load_types', 'wpestate_load_types' );
function wpestate_load_types(){
global $wpdb;
$typesVal = $_GET[type_slug];
foreach($typesVal as $k = $v){
add_query_arg( $k, $v);
}
wp_die();
}