When I use at the end of a post related posts. And I show e.g. 8 posts, but there are more, there apperas a paginator at the end of the8 related posts.
When I press the “2” for the next couple of 8 more posts, it does not show the next 8 posts, but it links to the last post in the group.
This is only the case for posts, it works fine in pages.
greetings Karl
Hey Karl,
Thank you for using Enfold.
This is actually a WordPress core issue. It’s not possible to add a pagination on single post pages without disabling the redirect.
Related thread:
https://wordpress.org/support/topic/pagination-issues-in-custom-singlephp-page/page/2/
https://wordpress.org/support/topic/url-rewriting-on-custom-post-type/
https://core.trac.wordpress.org/ticket/15551
There’s a solution but we are not sure if it’s not going to affect anything else.
add_action( 'template_redirect', function() {
if ( is_singular( 'post' ) ) {
global $wp_query;
$page = ( int ) $wp_query->get( 'page' );
if ( $page > 1 ) {
// convert 'page' to 'paged'
$query->set( 'page', 1 );
$query->set( 'paged', $page );
}
// prevent redirect
remove_action( 'template_redirect', 'redirect_canonical' );
}
}, 0 ); // on priority 0 to remove 'redirect_canonical' added with priority 10
Best regards,
Ismael