Как добавить разбиение на страницы на ajax в wordpress

Я хочу, чтобы разбивать мои результаты поиска ajax в ajax pagination, может кто-нибудь помочь в этом, чтобы попытаться найти Google, но я ничего не нашел. я нашел больше информации о wp_query, но данные thist не для меня, потому что я не использую сообщения

Моя функция ajax в функции.php для получения данных из таблицы:

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 "???µN‚ N€?µ?·N??»N?N‚?°N‚????";
}
   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>????N?: </span><?=$results->user_name;?></div>
        <div><span>?’???·??N€?°N?N‚: </span><?=$results->age;?></div>
        <div><span>??N‰?µN‚ ??????N?N‚N‡?????°(?Y???»): </span><?=$results->wm;?></div>
        <div><span>??N‚N€?°???° ??N‚??N‹N…?°: </span><?=get_the_title($id);?></div>
        <div><span>?”?°N‚?° ?????µ?·??????: </span><?=$results->date_start;?></div>
        <div><span>Email: </span><?=$results->email;?></div>
        <div><span>???µ?»: </span><?=$results->tel;?></div>
        <div><span>C?????±N‰?µ?????µ: </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>?”?°N‚?° N€?°?·???µN‰?µ?????µ: </span><?=$results->datestamp;?></div>
    </div>
</div>
 <?php


   }
echo paginate_links( array(
                        'base' => add_query_arg( 'cpage', '%#%' ),
                        'format' => '',
                        'prev_text' => __('&laquo;'),
                        'next_text' => __('&raquo;'),
                        'total' => ceil($total / $items_per_page),
                        'current' => $page
                    ));


    die; // ???°N‘?? ??????N?N‚N?, N‡N‚?? ???±N€?°?±??N‚N‡???? ?·?°??????N‡???» ??N‹?????»???µ?????µ
}

Мой javascript для вызова функции ajax из wp-admin-ajax.php:

<script>

jQuery(function($){
    $('#fld_551620_1').click(function(){
        $('#searchresults').html('');

        var country = document.getElementById("fld_8091734_1");
    var date_start =$('#fld_7900131_1').val();
    var date_end =$('#fld_6539646_1').val();
    var wm =$( "input[name='fld_3061011']:checked" ).val();
        $.ajax({
            url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",     
            type: 'POST', 
            data: {
    action:'search_ajax_call',
    country: country.options[country.selectedIndex].value,
    date_start: date_start,
    date_end: date_end,
    wm: wm,
},
beforeSend: function() {
        $('#loader').show();
    },
    complete: function() {
        $('#loader').hide();
    },
            success: function( data ) {
                $('#searchresults').html(data); 
            }
        });
        // ?µN??»?? N??»?µ???µ??N‚ a€“ N?N?N‹?»???°, N‚?? ???µ ?·?°?±N‹???°?µ??:
        // return false;
    });
});


</script>

ajax,wordpress,pagination,

1

Ответов: 0

Как добавить разбиение на страницы на ajax в wordpress

Я хочу, чтобы разбивать мои результаты поиска ajax в ajax pagination, может кто-нибудь помочь в этом, чтобы попытаться найти Google, но я ничего не нашел. я нашел больше информации о wp_query, но данные thist не для меня, потому что я не использую сообщения

Моя функция ajax в функции.php для получения данных из таблицы:

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 "???µN‚ N€?µ?·N??»N?N‚?°N‚????";
}
   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>????N?: </span><?=$results->user_name;?></div>
        <div><span>?’???·??N€?°N?N‚: </span><?=$results->age;?></div>
        <div><span>??N‰?µN‚ ??????N?N‚N‡?????°(?Y???»): </span><?=$results->wm;?></div>
        <div><span>??N‚N€?°???° ??N‚??N‹N…?°: </span><?=get_the_title($id);?></div>
        <div><span>?”?°N‚?° ?????µ?·??????: </span><?=$results->date_start;?></div>
        <div><span>Email: </span><?=$results->email;?></div>
        <div><span>???µ?»: </span><?=$results->tel;?></div>
        <div><span>C?????±N‰?µ?????µ: </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>?”?°N‚?° N€?°?·???µN‰?µ?????µ: </span><?=$results->datestamp;?></div>
    </div>
</div>
 <?php


   }
echo paginate_links( array(
                        'base' => add_query_arg( 'cpage', '%#%' ),
                        'format' => '',
                        'prev_text' => __('&laquo;'),
                        'next_text' => __('&raquo;'),
                        'total' => ceil($total / $items_per_page),
                        'current' => $page
                    ));


    die; // ???°N‘?? ??????N?N‚N?, N‡N‚?? ???±N€?°?±??N‚N‡???? ?·?°??????N‡???» ??N‹?????»???µ?????µ
}

Мой javascript для вызова функции ajax из wp-admin-ajax.php:

<script>

jQuery(function($){
    $('#fld_551620_1').click(function(){
        $('#searchresults').html('');

        var country = document.getElementById("fld_8091734_1");
    var date_start =$('#fld_7900131_1').val();
    var date_end =$('#fld_6539646_1').val();
    var wm =$( "input[name='fld_3061011']:checked" ).val();
        $.ajax({
            url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",     
            type: 'POST', 
            data: {
    action:'search_ajax_call',
    country: country.options[country.selectedIndex].value,
    date_start: date_start,
    date_end: date_end,
    wm: wm,
},
beforeSend: function() {
        $('#loader').show();
    },
    complete: function() {
        $('#loader').hide();
    },
            success: function( data ) {
                $('#searchresults').html(data); 
            }
        });
        // ?µN??»?? N??»?µ???µ??N‚ a€“ N?N?N‹?»???°, N‚?? ???µ ?·?°?±N‹???°?µ??:
        // return false;
    });
});


</script>
01Аякса, WordPress, нумерация страниц,
Похожие вопросы
Яндекс.Метрика