Answer the question
In order to leave comments, you need to log in
Pagination does not work correctly when switching, how to fix it?
How to fix the incorrect work of pagination, it considers correctly and displays page2, page3, but in fact the same posts are displayed on each page, and the rest are not displayed, here is the cycle code:
<div class="row">
<?php $args = array(
's' => get_search_query()
);
?>
<?php $the_query = query_posts( $args );
?>
<?php if ( ! empty( $the_query )) { ?>
<?php /* Start the Loop */ ?>
<?php
foreach ( $the_query as $post ) {
$cat = get_the_category();
$cat_ID= $cat[0]->term_id; ?>
<div class="search-result-post">
<div class="search-post-img">
<a href="<?php echo get_permalink(); ?>">
<?php if(get_the_post_thumbnail_url($post->ID)) echo get_the_post_thumbnail($post->ID); else echo ' <img alt="#" src="http://blogprogram.ru/wp-content/uploads/2016/05/noimg.png">';?>
</a>
</div>
<div class="search-result-detail">
<div class="search-result-detail-body">
<a href="<?= get_term_link($cat[0])?>" class="category-news"><?= get_cat_name($cat_ID);?></a>
<div class="search-result-post-bottom">
<p class="date-news"><?php the_time( 'j.m.Y'); ?></p>
<p class="posts-p"><a href="<?php the_permalink(); ?>" class="news-post-text"><?php the_title(); ?></a></p>
</div>
</div>
</div>
</div>
<?php } ?>
<?php the_posts_pagination( array(
'mid_size' => 4,
'end_size' => 1,
'prev_text' => 'Предыдущая',
'next_text' => 'Следующая',
) ); ?>
<?php } else {
echo '<p> По вашему запросу ничего найдено...</p>';
} ?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question