Created
April 26, 2018 08:12
-
-
Save GarySwift/b4367ff9ecccdd2db38938905721cc29 to your computer and use it in GitHub Desktop.
Using pagination on a CPT single page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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