我想在ajax分页中对ajax搜索结果进行分页 任何人都可以帮我分页吗,我尝试搜索谷歌,但是我什么也没找到。我找到了有关wp_query的更多信息,但是此数据不适合我,因为我不使用帖子
function.php中我的ajax函数用于从表中获取数据:
(10,1)
我的可从wp-admin-ajax.php调用ajax函数的javascript:
add_action( 'wp_ajax_search_ajax_call', 'search_ajax_call' );
add_action( 'wp_ajax_nopriv_search_ajax_call', 'search_ajax_call' );
function search_ajax_call(){
$country=$_POST['country'];
$date_start=$_POST['date_start'];
$date_end=$_POST['date_end'];
$wm=$_POST['wm'];
if ($country) {
$searchkeys.=" AND country='".$country."'";
}
if ($date_start) {
$searchkeys.=" AND date_start>".$date_start;
}if ($date_end) {
$searchkeys.=" AND date_end<".$date_end;
}if ($wm) {
$searchkeys.=" AND wm='".$wm."'";
}
global $wpdb;
$query = "SELECT fe.id, fe.form_id,fe.datestamp, fe.status, MAX(CASE WHEN fev.slug = 'avatar' THEN fev.value END) as avatar, MAX(CASE WHEN fev.slug = 'user_name' THEN fev.value END) as user_name, MAX(CASE WHEN fev.slug = 'message' THEN fev.value END) as message, MAX(CASE WHEN fev.slug = 'date_end' THEN fev.value END) as date_end, MAX(CASE WHEN fev.slug = 'date_start' THEN fev.value END) as date_start, MAX(CASE WHEN fev.slug = 'country' THEN fev.value END) as country, MAX(CASE WHEN fev.slug = 'tel' THEN fev.value END) as tel, MAX(CASE WHEN fev.slug = 'email' THEN fev.value END) as email, MAX(CASE WHEN fev.slug = 'age' THEN fev.value END) as age, MAX(CASE WHEN fev.slug = 'city' THEN fev.value END) as city, MAX(CASE WHEN fev.slug = 'wm' THEN fev.value END) as wm FROM wp_cf_form_entries fe INNER JOIN wp_cf_form_entry_values fev ON fev.entry_id = fe.id GROUP BY fe.id, fe.form_id, fe.status HAVING fe.id>'0' ".$searchkeys."";
$items_per_page = 10;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$offset = ( $page * $items_per_page ) - $items_per_page;
$total_query = "SELECT COUNT(1) FROM (${query}) AS combined_table";
$total = $wpdb->get_var( $total_query );
$result = $wpdb->get_results( $query.' ORDER BY id DESC LIMIT '. $offset.', '. $items_per_page, OBJECT );
if (!$result) {
echo "Нет результатов";
}
foreach( $result as $results ) {
if ( $post = get_page_by_path( $results->country, OBJECT, 'country' ) )
$id = $post->ID;
else
$id = 0;
?>
<style type="text/css">
#searchresults .row div{
font-size: 20px;
line-height: 1.5;
color: white;
}
#searchresults img {
max-height: 250px;
}
</style>
<div class="row ">
<div class="col-md-6 col-sm-12 data-traveler">
<div><span>Имя: </span><?=$results->user_name;?></div>
<div><span>Возвраст: </span><?=$results->age;?></div>
<div><span>Ищет попутчика(Пол): </span><?=$results->wm;?></div>
<div><span>Страна отдыха: </span><?=get_the_title($id);?></div>
<div><span>Дата поездки: </span><?=$results->date_start;?></div>
<div><span>Email: </span><?=$results->email;?></div>
<div><span>Тел: </span><?=$results->tel;?></div>
<div><span>Cообщение: </span><?=$results->message;?></div>
</div>
<div class="col-md-6 col-sm-12"><img src="<?=$results->avatar;?>"></div>
<div class="col-md-12 col-sm-12 data-traveler">
<div class="date"><span>Дата размещение: </span><?=$results->datestamp;?></div>
</div>
</div>
<?php
}
echo paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => ceil($total / $items_per_page),
'current' => $page
));
die; // даём понять, что обработчик закончил выполнение
}