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();
}

Topic urls Wordpress parameter

Category Web


This really needs more context in what apple and banana are referring to and what you're trying to accomplish and how you've already tried to accomplish it...

You could do a custom query and set the parameters in terms based on whatever was selected in the multiple choice. This is assuming that A. fruit is a CPT and that B. "apple" and "banana" are custom taxonomies of "type" associated with the fruit CPT.

$args = array(
    'post_type' => 'fruit',
    'tax_query' => array(
        array(
            'taxonomy' => 'type',
            'field'    => 'slug',
            'terms'    => array( 'apple', 'banana' )
        )
    )
);
$query = new WP_Query( $args );

New queries can cause issues with pagination if that's a concern so use with caution.

You may also want to consider checking out the pre_get_posts filter, here is an article/question-answer thread that helped me get a form with custom options that queries a CPT and it's taxonomy set up: Wordpress custom search form with pre_get_posts not work

(just noticed the ajax part)

You can also make requests through the wp api and get back multiple categories from a post type like so:

/wp-json/wp/v2/posttype?category=3,4

Replace posttype with your post type name and category with the taxonomy name you are trying to access, finally replace 3,4 with whatever the ID's of the category are. So your query might look something like below, assuming fruit is the name of the post type and 5 is the ID of apple and 9 is the ID of banana ( for example )

/wp-json/wp/v2/fruit?category=5,9

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.