1ответ(ов) в теме
Доброго времени суток.
Я переопределил вывод карты на свою функцию вместо the_content().
И при переходе на пост все работает, но...
function the_article_map() {
$content = apply_filters( 'the_article_map', $content );
return $content;
}
Сделал через ajax вывод содержимого поста в модалке на странице архивов, все выводится кроме карты.
Приходит null.
Содержимое function.php.
Пытаюсь вывести через свою функцию the_article_map().
function load_post_content_with_comments() {
$post_id = $_POST['post_id'];
$post = get_post($post_id);
$comments = get_comments(array(
'post_id' => $post_id,
'status' => 'approve', // Учитываем только одобренные комментарии
));
// Вывод контента модалки
exit;
}
Содержимое JS
Спойлер
$(document).ready(function() {
$(document).on('click', '.open-post-modal', function(e) {
e.preventDefault();
var post_id = $(this).data('postid');
$.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: 'load_post_content_with_comments',
post_id: post_id
},
success: function(response) {
$('#modal-content').html(response);
// Проверка вновь загруженных постов
if ($('#posts-container').find('.post').length > 0) {
// Здесь можете добавить код для обработки вновь загруженных постов
// console.log('Новые посты загружены');
} else {
// Здесь можете добавить код для обработки, если посты не были загружены
// console.log('Посты не были загружены');
}
},
error: function(xhr, status, error) {
console.error(error);
}
});
});
$(document).on('submit', '#comment-form', function(e) {
e.preventDefault();
var formData = $(this).serialize();
$.ajax({
type: 'POST',
url: ajaxurl,
data: formData,
success: function(response) {
// Дополнительные действия после успешного добавления комментария
$('#comment-message');
const commload = document.querySelector('#send-outline');
commload.style.color = 'red';
// Обновить список комментариев
$.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: 'load_post_content_with_comments',
post_id: $('#comment-form input[name="post_id"]').val()
},
success: function(response) {
$('#modal-content').html(response);
},
error: function(xhr, status, error) {
console.error(error);
}
});
},
error: function(xhr, status, error) {
console.error(error);
}
});
});
});
Как можно еще попробовать получить данные карты?
Вы не имеете права на публикацию сообщений в этой теме