将jQuery滑块值传递给GET

时间:2015-05-25 21:39:41

标签: wordpress jquery-ui

我正在尝试从jQuery滑块中获取值并将它们传递给GET,以便在Wordpress中进行元搜索。目前我的代码在输入字段下面通过url传递此数据:&price=Between+5000+and+25000+currency.

处理/获取此值的最佳方法是什么,以便我可以将它们传递给我的php元搜索功能。

jQuery(function() {

$( "#slider-range" ).slider({
    range: true,
    min: 0,
    max: 100000,
    values: [ 5000, 25000 ],
    slide: function( event, ui ) {

        $( "#amount" ).val( "Between " + ui.values[ 0 ] + " and " + ui.values[ 1 ] + " currency.");
    }

});

$( "#amount" ).val( "Between " + $( "#slider-range" ).slider( "values", 0 ) + " and " + $( "#slider-range" ).slider( "values", 1 ) + " currency." );
});

1 个答案:

答案 0 :(得分:0)

我找到了自己的解决方案。仍在寻找更好或更优雅的处理方式。这是我的解决方案:

   if( !empty($_GET['price']) ) { // Checked GET request

            $pricesRange = $_GET['price'];

            preg_match_all('!\d+!', $pricesRange, $matches); // Extract only the numbers

            $rangeValue1 = $matches[0][0]; //preg_match_all returns multidimension array? 
            $rangeValue2 = $matches[0][1];

            $meta_query[] = array(
                'key'       => 'price',
                'value'     => array($rangeValue1, $rangeValue2 ),
                'type'      => 'DECIMAL',
                'compare'   => 'BETWEEN',
            );
    }