Skip to content

Instantly share code, notes, and snippets.

@GarySwift
Created April 26, 2018 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GarySwift/b4367ff9ecccdd2db38938905721cc29 to your computer and use it in GitHub Desktop.
Save GarySwift/b4367ff9ecccdd2db38938905721cc29 to your computer and use it in GitHub Desktop.
Using pagination on a CPT single page
<?php
/**
* Adding pagination for CPT section
*
* This is fix for using pagination on a CPT single page
*
* @link https://wordpress.stackexchange.com/questions/233885/yet-another-custom-post-type-with-pagination-not-working-in-wordpress
*
* @param $request
*/
function fix_request_redirect( $request ) {
$cpt = 'section';//Change this to the CPT slug
if ( isset( $request->query_vars[$cpt] )
&& true === $request->is_singular
&& - 1 == $request->current_post
&& true === $request->is_paged
) {
add_filter( 'redirect_canonical', '__return_false' );
}
return $request;
}
add_action( 'parse_query', 'fix_request_redirect' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment