Finally got pagination to work with the below code, but now the pagination links to /videos/page/2/, which doesn’t exist. How do I get page 2 to work?
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=videos&showposts=1'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
//display stuff
endwhile;
php wp_pagenavi();
?>
Found the answer:
After a long time I found a solution for this issue (thanks to franzblog).
If you are using version 4.2 or higher, you need to add the following lines in your
functions.php
file:Everything is working fine now!
Maybe tree years ago it was impossible, but now you CAN.
First, add this lines to
$args
into your post type:Second, in
functions.php
add action:Don’t forget to flush rules in dashboard.
One possibility is that, on the admin dashboard
Settings -> Reading
, if you have selected aPosts page
, the optionBlog pages show at most
will conflict with your customposts_per_page
query in that page.So make sure that you either unselect the posts page, or make sure the posts per page matches the
Blog pages show at most
option inSettings -> Reading
.After debugging a long time even I got the solution regarding pagination issue
Basically, In WordPress, you can’t have a PAGE and a CUSTOM POST TYPE with the same name. If you do, the permalink rewrite rules will get confused and trigger a 404.