I thought I know how to add pagination to a custom loop and I've seen these questions and tutorials:
- Pagination not working with custom loop
but for some reason it doesn't work at this time. I created myfile.php, named it to "My Page Template" and set that to be my front page in Admin Panel > Settings > Reading.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => array('my_custom_post_type'), 'paged' => $paged, 'posts_per_page' => 3, 'ignore_sticky_posts' => 1 ); $wp_query = new WP_Query( $args ); var_dump($wp_query); if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); // show post endwhile; endif; next_posts_link('Next posts'); wp_reset_query(); wp_reset_postdata();
- Front page shows 3 posts as expected.
- "Next posts" link is shown and points to http://example.com/page/2/ as expected.
- While I'm on http://example.com/page/2/ it shows the same set of posts and "Next posts" link points to http://example.com/page/2/ which is not what I want.
public 'max_num_pages' => float 8.
public 'found_posts' => string '24' (length=2).
public 'is_paged' => boolean false.
'paged' => int 1(when I'm on page number 2).
- When I'm renaming
$my_custom_querythen "Next posts" link doesn't show at all.
Is there anything else I should do here?
I managed to set proper
$paged by changing
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; to
$paged = (get_query_var('page')) ? get_query_var('page') : 1; but it still shows a wrong navigation link.