Интересно, кто-нибудь может помочь, потому что это сводит меня с ума. У меня есть страница архива со списком новостей. Теперь этими новостями управляет ajax-вызов, чтобы заполнить и изменить их на основе выпадающих списков, состоящих из пользовательских таксономий (в данном случае 3 из них - темы, сектора и технологии). В любом случае, проблема, с которой я столкнулся, заключается в том, что я не могу заставить нумерацию страниц работать ни на одном из постов. Нет, это как-то связано с вызовом ajax и функцией, вызывающей его, но я не могу заставить его работать. Мне удалось заставить его отображать номера нумерации страниц, но когда я нажимаю на них, я перехожу на мой веб-адрес / wp-admin / wp-ajax.php, что, очевидно, неверно. Я не занимался этим долго, поэтому любая помощь или руководство могли бы помочь.
var base = window.location.pathname + window.location.search;
var technologies = document.querySelector('#category').value;
var sectors = document.querySelector('#sectors').value;
var topics = document.querySelector('#topics').value;
var sort = document.querySelector('#sort').value;
var type = window.location.pathname.split('/')[1];
var ajaxurl = 'http://www.mywebsite.com/wp-admin/admin-ajax.php';
jQuery.ajax({
type: 'GET',
url: ajaxurl,
data: {
"action": "load_news",
tech: '*' ,
sector: '*' ,
topic: '*' ,
sorting: sort,
type:type,
base:base
},
success: function(response) {
jQuery(".news-slider").html(response);
return false;
}
});
Выше мой jjery-вызов ajax, а ниже - functions.php
add_action( 'wp_ajax_nopriv_load_news', 'prefix_load_term_news' );
add_action( 'wp_ajax_load_news', 'prefix_load_term_news' );
function prefix_load_term_news () {
$tech_id = $_GET[ 'tech' ];
$sector_id = $_GET[ 'sector' ];
$topic_id = $_GET[ 'topic' ];
$sort_filter = $_GET['sorting'];
$type = $_GET['type'];
$base = $_GET[ 'base' ];
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array (
'post_type' => $type,
'posts_per_page' =>2,
'paged' => $paged,
'order' => $sort_filter,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'taxonomy-news',
'field' => 'id',
'terms' => $tech_id,
),
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $sector_id,
),
array(
'taxonomy' => 'taxonomy-topics',
'field' => 'id',
'terms' => $topic_id,
),
),
);
try {
$postslist = new WP_Query($args);
$big = 999999999; // This needs to be an unlikely integer
// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link($big) ),
'current' => max( 1, $postslist->get( 'paged' ) ),
'total' => $postslist->max_num_pages,
) );
// Display the pagination if more than one page is found
if ( $paginate_links ) {
echo '<div class="pagination">';
echo $paginate_links;
echo '</div><!--// end .pagination -->';
}
}
catch (Exception $error) {
echo 'An error occurred while loading news posts. Please try again.';
}
?>
<?php if ( $postslist->have_posts() ) :
while ( $postslist->have_posts() ) : $postslist->the_post();
include('template-parts/content-archive-ajax.php');
endwhile;
wp_reset_postdata();
endif;
}