jeudi 22 décembre 2016

Wordpress - ACF checkbox filter (URL ISSUE)

LINK : http://ift.tt/2i7uyOH

Ok im trying to create filter checkbox for default WP posts jquery/js with ACF plugin based on this guide http://ift.tt/2i0I8G8. it works well at the first filter, the url add "?sale-book-subject=value-of-checkbox,another-value-of-checkbox,anotherone,etc" for "CATEGORY" filter

but when i try to filter by "CONDITION" checked 2 checkboxes the url added 2 keys instead of one like "&sale-book-condition=value-of-checkbox&sale-book-condition=value-of-checkbox"

it needs to be

"&sale-book-condition=value-of-checkbox,value-of-checkbox,another,value-of-checkbox," separated by ","

heres my js/jquery for CONDITION filter

<script>

$('#condition-filters ul li').on('change', 'input[type="checkbox"]', function(){    
    if (window.location.href.indexOf("sale-book-subject") > -1) { // IF KEY "sale-book-subject" exist in URL 
        var cname = '<?php echo $field_condition['name']; ?>';  // GET KEY 
        var condition_value = window.location.href + "&" + cname + "=";  // ADD CURRENT URL + KEY = VALUE

        $("input.condtion").each(function() {
            var conditionchecked = $(this).is(":checked");
            if (conditionchecked) {
                condition_value + $(this).val() + ","; 

                // checkbox_value = checkbox_value.join(', ');                              
                window.location = condition_value;
            }
        });
        return false;

    } else {
        var cname = '<?php echo $field_condition['name']; ?>'; // GET KEY 
        var condition_value = "<?php echo home_url('list-filter'); ?>" + "?" + cname + "="; // URL + KEY = VALUE

        $(":checkbox").each(function() {
            var ischecked = $(this).is(":checked");
            if (ischecked) {
                condition_value += $(this).val() + ",";

                // checkbox_value = checkbox_value.join(', ');  

                window.location = condition_value;
            }
        });
        return false;
    }   
    </script>




Aucun commentaire:

Enregistrer un commentaire