Answer the question
In order to leave comments, you need to log in
How to correctly implement post type pagination on a page?
There is such a code, it displays 2 posts out of 7 created and displays pagination that 4 pages, but when you click on the navigation, it simply updates the page with the same posts and in the address bar ( http:// site address/feedback/page/3/) changes to the pagination page number, maybe an error in the code? Thank you in advance for any advice
<div class="row-short-post">
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=2&post_type=feedback' . '&paged=' . $paged);
while ($wp_query->have_posts()):
$wp_query->the_post();
$excerpt_reviews = get_the_excerpt();
?>
<div class="col-short-post">
<div class="short-post-video">
<?php the_post_thumbnail(); ?>
<div class="short-post-overlay">
<img src="<?php the_field('logo_company_feedback'); ?>" alt="">
</div>
</div>
<a class="short-post-author" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span class="short-post-author-position"><?php the_field('position_company_feedback'); ?></span>
<div class="short-post-author-text">
<?php echo excerpt(25); ?>
</div>
<a class="short-post-author-more" href="<?php the_permalink(); ?>">
<span>Читать отзыв</span>
<img src="img/covid/arrow_light.svg" alt="">
</a>
</div>
<?php
endwhile; ?>
</div>
<div class="paginations">
<?php
//global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links(array('base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $wp_query->max_num_pages, 'prev_text' => '«', 'next_text' => '»'));
?>
</div>
<?php
$wp_query = null;
$wp_query = $temp;
?>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
wrote all the same, only in his own words, try:
<div class="row-short-post">
<?php
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'posts_per_page' => 2,
'post_type' => 'feedback',
'paged' => $paged,
);
$wp_query = new WP_Query($args);
?>
<?php if ( $wp_query->have_posts() ) : ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div class="col-short-post">
<div class="short-post-video">
<?php the_post_thumbnail(); ?>
<div class="short-post-overlay">
<img src="<?php the_field('logo_company_feedback'); ?>" alt="">
</div>
</div>
<a class="short-post-author" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span class="short-post-author-position"><?php the_field('position_company_feedback'); ?></span>
<div class="short-post-author-text">
<?php echo excerpt(25); ?>
</div>
<a class="short-post-author-more" href="<?php the_permalink(); ?>">
<span>Читать отзыв</span>
<img src="img/covid/arrow_light.svg" alt="">
</a>
</div>
<?php endwhile;?>
<?php endif; wp_reset_query(); ?>
</div>
<div class="paginations">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages,
'prev_text' => '«',
'next_text' => '»',
) );
?>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question