-1
Hello, good morning!
Well, I created a custom post for a Wordpress site and would like to add pagination to the loop, for that I am trying to use the function paginate_links() and the parameters used in the examples of this.
I inserted the pagination after the loop and the page count occurs correctly, but regardless of which page I click always shows the same posts.
I am using Wordpress 5.4, in permalink settings the option "Post name" and tested if there is any problem with other plugins.
Follow the code I’m trying to use.
$id_user = get_current_user_id();
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'posts_per_page' => 5,
'post_type' => 'serviceorder',
'paged' => $paged,
'meta_key' => 'cliente',
'meta_value' => $id_user
);
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a><br>
<?php // $whoareyou = the_field('cliente'); ?>
</li>
<?php endwhile; ?>
<?php
$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' => $the_query->max_num_pages,
) );
?>
</ul>
<?php else: ?>
<p>Você não tem nenhuma OS registrada.<p>
<?php endif; ?>
<?php wp_reset_query();