Php 在AJAX post filter中添加多个元键和值

Php 在AJAX post filter中添加多个元键和值,php,jquery,html,ajax,wordpress,Php,Jquery,Html,Ajax,Wordpress,我为自定义字段值创建了一个AJAX后期过滤器。此过滤器通过JSON迭代呈现数据,并使用自定义内容模板。该代码非常适用于自定义字段品牌,其中有值 现在我面临的问题是在函数中添加多个元键,之后我将能够过滤多个自定义值字段 如何在函数中添加多个键和值$args? Function.php 剧本 jQuery(文档).ready(函数(){ jQuery('.br')。单击(函数(){ jQuery('.contents').remove(); var checked=jQuery('#test').

我为自定义字段值创建了一个AJAX后期过滤器。此过滤器通过JSON迭代呈现数据,并使用自定义内容模板。该代码非常适用于自定义字段品牌,其中有

现在我面临的问题是在函数中添加多个元键,之后我将能够过滤多个自定义值字段

如何在函数中添加多个键和值
$args

Function.php

剧本


jQuery(文档).ready(函数(){
jQuery('.br')。单击(函数(){
jQuery('.contents').remove();
var checked=jQuery('#test').serialize();
$('.filter output').empty()
jQuery.ajax({
url:“”,
数据:“操作=调用\发布和模板=内容-”+选中,
成功:功能(结果){
jQuery(result).appendTo('.filter output');
}
});
})
});
Form.php

<form  id='test' >
<input type="checkbox" name="mobile[]" value="Nokia" class="br"> NOKIA 
<input type="checkbox" name="mobile[]" value="LG" class="br"> LG 
    <div class="filter-output">
        </div>
</form>

诺基亚
LG

是的,使用第三个参数
'compare'
可以轻松完成

'meta\u query'还包含一个或多个具有以下键的数组:

键(字符串)
-自定义字段键。

'value'(字符串|数组)
-自定义字段值。仅当比较为“IN”、“NOT IN”、“BETWEEN”或“NOT BETWEEN”时,它才可以是数组。在WordPress 3.9及更高版本中使用“存在”或“不存在”比较时,无需指定值。
注意:由于bug#23268,3.9之前的NOT EXISTS比较需要值才能正常工作。您必须为value参数提供一些字符串。空字符串或NULL将不起作用。但是,任何其他字符串都会起作用,并且在使用NOT EXISTS时不会显示在SQL中。需要灵感吗?关于'bug#232如何68.)


'compare'(字符串)
-要测试的运算符。可能的值为“=”、“!=”、“>”、“>=”、“如何使用“$brand=$params['mobile'];”对于每个键,您可以将任何参数(如
'key'
)替换为变量(如
'key'=>$variable
),对于
'value'
)也是如此。这是可行的,我已经使用过了…但是
'relation'
'compare'
参数对于获得所需的内容非常重要。这就像一个SQL查询…
<script>
   jQuery(document).ready(function () {
     jQuery('.br').click(function () {
        jQuery('.contents').remove();
        var checked = jQuery('#test').serialize();
        $('.filter-output').empty()
        jQuery.ajax( {
            url: "<?php echo admin_url('admin-ajax.php'); ?>",              
            data: "action=call_post&template=content&" + checked,
            success: function (result) {
            jQuery(result).appendTo('.filter-output');
            }
        });
    })
 });
</script>
<form  id='test' >
<input type="checkbox" name="mobile[]" value="Nokia" class="br"> NOKIA 
<input type="checkbox" name="mobile[]" value="LG" class="br"> LG 
    <div class="filter-output">
        </div>
</form>
$args = array(
    'post_type' => 'post',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'brand',
            'value' => $brand,
            'compare' => '=',
        ),
        array(
            'relation' => 'AND',
            array(
                'key' => 'color',
                'value' => 'red',
                'compare' => '=',
            ),
            array(
                'key' => 'size',
                'value' => 'small',
                'compare' => '=',
            ),
        ),
    ),
);