Приветствую, я реализовал ajax вывод постов через кнопку, по принципу Load More. Я загружаю только первые 5 страниц произвольного типа записей по 6 штук. Итого всего я подгружаю 30 записей подобного типа.
Вопрос: Как мне задать определенные записи для подгрузки, к примеру по по ID?
JS:
let currentPage = 1;
$('#load-more').on('click', function() {
currentPage++;
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
dataType: 'json',
data: {
action: 'weichie_load_more',
paged: currentPage,
},
success: function (res) {
if(currentPage >= res.max) {
$('#load-more').hide();
}
$('.property-grid').append(res.html);
}
});
});
PART:
<?php if ( $get_resales->have_posts() ) : ?>
<div class="row gy-4 property-grid">
<?php while ( $get_resales->have_posts() ) : $get_resales->the_post();
get_template_part('parts/property-item','',$post->ID);
endwhile; ?>
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<div class="text-center property__btn">
<a href="#!" class="btn btn-outline-lightInDark text-white fw-normal" id="load-more"> Show More <span class="icon-right"> <i class="fas fa-arrow-right"></i> </span> </a>
</div>
FUNCTION:
function weichie_load_more() {
$ajaxposts = new WP_Query([
'post_type' => 'resales',
'posts_per_page' => 6,
'orderby' => 'date',
'order' => 'DESC',
'paged' => $_POST['paged'],
]);
$response = '';
// $max_pages = $ajaxposts->max_num_pages; // безлимит
$max_pages = 5;
if($ajaxposts->have_posts()) {
ob_start();
while($ajaxposts->have_posts()) : $ajaxposts->the_post();
$response .= get_template_part('parts/property-item', 'publication');
endwhile;
$output = ob_get_contents();
ob_end_clean();
} else {
$response = '';
}
$result = [
'max' => $max_pages,
'html' => $output,
];
echo json_encode($result);
exit;
}
add_action('wp_ajax_weichie_load_more', 'weichie_load_more');
add_action('wp_ajax_nopriv_weichie_load_more', 'weichie_load_more');