You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.8 KiB
46 lines
1.8 KiB
jQuery(document).ready(function ($) {
|
|
$('#ajax-load-author').on('submit', function (e) {
|
|
e.preventDefault();
|
|
var form = $(this);
|
|
var currentPage = parseInt($('#page_num').val());
|
|
var totalPosts = parseInt(form.data('total'));
|
|
var postsPerPage = 9;
|
|
|
|
console.log('Current page before load:', currentPage);
|
|
console.log('Total posts:', totalPosts);
|
|
console.log('Posts loaded before request:', postsPerPage);
|
|
|
|
var data = {
|
|
action: 'get_author_posts',
|
|
page_num: currentPage,
|
|
author_id: form.data('author')
|
|
};
|
|
|
|
console.log('Sending AJAX request with data:', data);
|
|
|
|
$.ajax({
|
|
url: '/wp-admin/admin-ajax.php',
|
|
type: 'POST',
|
|
data: data,
|
|
success: function (response) {
|
|
console.log('AJAX response received');
|
|
$(".anons-article__card-wrap").append(response);
|
|
|
|
$('#page_num').val(currentPage + 1);
|
|
console.log('New page number:', currentPage + 1);
|
|
|
|
// Считаем общее количество загруженных постов
|
|
var currentlyDisplayed = $('.anons-article__card-wrap .anons-best__card').length;
|
|
console.log('Actually displayed posts:', currentlyDisplayed);
|
|
|
|
if (currentlyDisplayed >= totalPosts) {
|
|
console.log('Hiding load more button - all posts loaded');
|
|
form.hide();
|
|
}
|
|
},
|
|
error: function (error) {
|
|
console.error('AJAX error:', error);
|
|
}
|
|
});
|
|
});
|
|
});
|