Wordpress - ACF复选框过滤器(URL ISSUE)

时间:2016-12-23 03:24:58

标签: javascript php jquery wordpress advanced-custom-fields

LINK:http://www.danielternes.com/formtest/list-filter

好的我试图根据本指南https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter为默认WP创建过滤器复选框,使用ACF插件发布jquery / js。 它适用于第一个过滤器,url add"?sale-book-subject = value-of-checkbox,another-value-of-checkbox,anotherone等"为" CATEGORY"过滤

但是当我尝试过滤" CONDITION"选中2个复选框,网址添加了2个密钥,而不是一个像 "&安培;销售图书条件=值的-复选框&安培;销售图书条件=值的-复选框"

它需要

"&安培;销售图书条件=值的-复选框,值的-复选框,另一个,价值的-复选框"由","

分隔

继承人我的js / jquery为CONDITION过滤器

<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>

0 个答案:

没有答案