I would like to output related posts on a custom post-type single page. Everything seems to be set up correctly. When I hover over my pagination links I see http://example.com/post-type-slug/post-slug/page/2/
. When I click I go to that page, but then get redirected back to the first page: http://example.com/post-type-slug/post-slug/
This is how I’ve set up my post type:
register_post_type( 'posttype',
array(
'rewrite' => array(
'slug' => 'post-type-slug',
'with_front' => false,
),
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => false,
'menu_position'=>5,
)
);
This is how I am doing my WP_query on the single page
$queryArgs = array(
'posts_per_page' => 3,
);
$queryArgs['paged'] = get_query_var( 'page' ) ? get_query_var('page') : 1;
$customQuery = new WP_Query( $queryArgs );
For my pagination I am using the method described here: https://wordpress.stackexchange.com/a/172818/10595
Why do I get redirected to the index? What can I do to prevent this.
I checked out some things:
When I disable pretty permalinks the pagination links say http://example.com/? posttype=post-slug&paged=2
. When I manually change that to http://example.com/? posttype=post-slug&page=2
everything works as I want it to. How can I alter my pagination to do this for me?