custom post type pagination using pre_get_posts

Here’s 1 function and 1 hook for custom post type pagination. Resolves the Page Not Found 404 pagination error by using pre_get_posts.

  • Call “customLoopWithPagination” function from the archive-posttype.php template.
  • Add the pre_get_posts action hook to your functions file
  • Resave your permalinks from wp-admin to flush the permalink cache
  • When you register your post type, set the rewrite url value to be different from the post type name

The action hook (functions.php)

The loop with pagination (archive-posttype.php)

Comments are closed.