Skip to content

Instantly share code, notes, and snippets.

@khleomix
Last active February 16, 2022 20:34
Show Gist options
  • Save khleomix/5d2215abdb4338011ba3aa645a99c5d0 to your computer and use it in GitHub Desktop.
Save khleomix/5d2215abdb4338011ba3aa645a99c5d0 to your computer and use it in GitHub Desktop.
Fix for error 404 on last page If using custom pagination for custom post type and with different posts_per_page value from settings. Add to functions.php/queries.php
<?php
/**
* Fix pagination on archive pages
*
* @author JC Palmes
*/
function khleomix_remove_page_from_query_string( $query_string ) {
if ( isset( $query_string['name'] ) == 'page' && isset( $query_string['page'] ) ) {
unset( $query_string['name'] );
$query_string['paged'] = $query_string['page'];
}
return $query_string;
}
add_filter( 'request', 'khleomix_remove_page_from_query_string' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment