I’ve setup a custom query for my posts (single.php) with pagination, which by the way is working great with the default permalink structure.
domain.com/p=ID&paged=2
if I switch the permalinks to /%postname%/ the page/2/ redirects to the first page.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array( 'connected_type'=> 'posts_to_posts', 'posts_per_page' => 3, 'paged' => $paged, 'order' => 'ASC', 'connected_items' => get_queried_object() );
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query( $args );
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
<?php endwhile; endif; $wp_query = null; $wp_query = $temp; wp_reset_query(); ?>
What’s confusing me is the fact that ir’s working with the default permalinks, why isn’t in working with the “pretty” links?
Homepage pagination is working fine, just the post page that’s messed up somehow. Can anyone point me to the right direction? where should I be looking for errors?
I’ve deactivated all plugins, deleted htaccess and created a new one, still nothing.
If anyone comes across this issue, you can add this to your functions.php code
Source
It is very old custom post type pagination issue.
And has open issue on wordpress core development tracker
The last workaround fix that figure in tracker was these one below. It working great for me.
If this is not the main loop. aka (Blog Page) WordPress will interprets the /2 as a subpage name and not as a paging query_var.
If you want this to work on a page you need to registers a custom query_var http://codex.wordpress.org/WordPress_Query_Vars and make the structure /page/paging/2 for example.