Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 14, 2021 14:15
Show Gist options
  • Save jorpdesigns/d96a6061d8a54b4851d56e5bfcccd646 to your computer and use it in GitHub Desktop.
Save jorpdesigns/d96a6061d8a54b4851d56e5bfcccd646 to your computer and use it in GitHub Desktop.
Snippet to set pagination rewrite rule for custom post type
<?php
add_action('init', 'custom_post_type_pagination_rewrite');
function custom_post_type_pagination_rewrite() {
$archiveSlug = 'archive-slug'; // Replace with the archive page slug
$archiveID = 55; // Replace with the archive page ID
add_rewrite_rule( $archiveSlug . '/page/?([0-9]{1,})/?$', 'index.php?page_id=' . $archiveID . '&paged=$matches[1]', 'top');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment