I am trying to paginate list of custom post types. This list shows okay, but I can’t seem to make pagination links to show.
Here is the code:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'families',
'posts_per_page' => 9,
'paged'=>$paged
);
$the_query = new WP_Query( $args );
?>
<table class="families">
<tr>
<th class="family_head">Family Head</th>
<th class="address">Address</th>
<th class="contact_number">Contact number</th>
</tr>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<tr>
<td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
<td><?php the_field( 'residence_address' ); ?></td>
<td class="contact_number"><?php the_field( 'mobile_number_1' ); ?></td>
</tr>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php else: ?>
<?php endif; ?>
</table>
Other similar WP functions for pagination aren’t working either. What am I doing wrong?
I erased all the code for pagination and re-did it. It works now. See if you can find the change.
Here is the working code –
I think that is the problem of get_query_var(‘paged’),Where you are using this code, have checked $paged,
Try to replace this
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
There is a difference between page vs. paged.
You can read more HERE
Hope, this will help. You can ask if may i help you further.Thanks