我在管理区内制作了搜索插件,并将此代码用于搜索
var currpeged =1;
var pperpage=50;
jQuery(document).on(\'click\',\'#search,#next,#prev\',function(e) {
// click search
e.preventDefault();
jQuery(\'.search-result\').html(\'<p class="text-center"><img src="../wp-admin/images/loading.gif"></p>\');
if (jQuery(\'#showperpage\').length == 1 ) {
pperpage = parseInt(jQuery(\'#showperpage\').val());
}
var id=jQuery(this).attr(\'id\');
if(id == \'prev\'){
if(currpeged <= 1){
currpeged=1;
} else{
currpeged-=1;
}
}
if(id==\'next\'){
currpeged = currpeged + 1;
}
var srch={
filter1:jQuery(\'#filter1\'),
filter2:jQuery(\'#filter2\'),
currp:currpeged,
perpage:pperpage,
};
jQuery.post(ajaxurl,{
\'action\': \'search_do\',
\'param\': srch
}
}).success(function(response){
jQuery(\'.search-result\').html(\'\');
for (var i = 0; i < response.length; i++) {
jQuery(\'.search-result\').append(response[i]);
}
});
});
负责搜索的php代码是:
$param = $_POST[\'param\'];
$str_m=\'\';
if(is_array( $param)){
$data = new stdClass();
foreach ($param as $key => $value)
{
$data->$key = $value;
}
}
$args_tt=array();
$args=array();
$query = new WP_Query(array(
\'post_type\' => \'custom-post\', // name of post type.
\'posts_per_page\' => 100,
\'orderby\' => \'meta_value_num\',
\'meta_key\' => $str_m,
\'order\' => \'ASC\',
\'meta_query\' => $args,//filters
\'paged\' => intval($data->currp)+1 //from object
));
当我搜索时,我得到了结果,但分页不起作用,currp永远不会递增,结果仍然与以前一样没有分页,请帮助,谢谢。