Using $paged redirects /page/2 to page 1

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="https://wordpress.stackexchange.com/questions/129486/<?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.

3 Answers
3

If anyone comes across this issue, you can add this to your functions.php code

add_filter('redirect_canonical','pif_disable_redirect_canonical');

function pif_disable_redirect_canonical($redirect_url) {
    if (is_singular()) $redirect_url = false;
return $redirect_url;
}

Source

Leave a Comment