Don’t create a new query and loop just to alter posts per page. Add a function hooked to pre_get_posts and alter whatever parameters you want in there before the query is run. This would go in your theme’s functions.php file, or a plugin.
function wpd_testimonials_query( $query ){
if( ! is_admin()
&& $query->is_post_type_archive( 'testimonials' )
&& $query->is_main_query() ){
$query->set( 'posts_per_page', 5 );
}
}
add_action( 'pre_get_posts', 'wpd_testimonials_query' );
Then in the template you run the normal loop and pagination works as expected.
Related Posts:
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Pagination not working with custom loop
- Have different number of posts on first page
- Custom post type pagination 404 fix?
- wp_pagenavi() with custom wp_query()?
- Pagination throws 404 error on custom taxonomy archive pages
- Custom Post Type Pagination Not Working On Archive Page
- Multiple Paginations on one Page
- Custom Post Type Archives by Date (stored as meta value) WP3.1
- Pagination go to first page if i’m on last post
- Posts in Multiple Columns and Rows with one single loop
- Newer/Older posts links display same posts on every page
- Custom post type archive with pagination?
- paginate function in archive for custom-post-type
- Fix custom query pagination without changing site-wide posts-per-page settings
- Pagination with custom post types results in 404 issues
- How to list custom post types?
- Custom post type archive page pagination
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- How can i change the output of posts_nav_link();
- How to display all posts from standard posts to custom post types in a loop with pagination?
- Paging doesn’t work?
- The loop seems stuck to a single (now deleted) post
- Custom Theme With Custom Loops
- Custom Post Types strange pagination problem
- pagination not working for category.php (custom post types in categories)
- Pagination Error : Duplicate argument being outputted
- Custom Post Type Archive Pagination
- pre_get_posts works in post type archive but not in single post
- Custom Post Type, Pagination and 404s?
- How can I increase the post count for custom post types only?
- Custom post type pagination error
- Custom archive page for custom taxonomy and pagination issue
- Custom post type paging return home page
- Pagination not working in custom post type. Help
- Pagination Not Working When Used With WP_Query() `offset` Property
- Custom WordPress theme not displaying posts from category
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- Custom post type pagination problem – page 1 and 2 show same content
- next_posts_link() always generates second page link on custom post type
- 2 custom posts types, in their own columns, one pagination for both
- How to Fix Custom WordPress Loop with Pagination on Single Post View?
- Pagination on custom post types
- Pagination in custom post type page template
- Custom post type archive pagination with HTML5Blank theme?
- paging is not working properly on news archives page [duplicate]
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Fourth page of custom post type archive page does not exist
- Pagination not working for archive
- Unable to display paging navigation with a custom post type loop
- WPNavi pagination links not working on custom pages
- Query Multiple Post Types and Paginate Newly Created List
- Custom Post Type Archives by Year & Month?
- Why are posts from custom post type not displayed in “category” archive?
- List all posts commented by current user
- Change title in head on Archive page
- Retrieving 3 latest post from each of 5 different custom post types
- How to solve suspected memory issue in custom WordPress loop?
- Display “Post 2 of 4” on single post page?
- Custom Post Type with static page for archive
- How to show the archive / post type description on Single templates
- is_main_query() not working for WP REST API
- Get next and previous 3 posts in a term in single post page
- Why is my site using index.php instead of archive?
- Listing all term items alphabetically / sorting loop
- Number of posts in the archive
- the_post() is printing titles in page footer
- Two column layout with alphabetical ordering
- Can anyone clarify difference between archive-{posttype}.php, type-{posttype} and date.php?
- Dynamically insert code to custom post type loop
- Pull in taxonomy field of custom post type in new query
- Posts are not rendering perfectly [closed]
- Pagination for custom post types – url rewriting
- Looping through custom taxonomy and display custom post types (Custom Post Type UI)
- Get post-meta value of all custom-posts – lowest to highest year-count?
- Custom Post Type Query W/Category Dropdown
- On click some element i want to use some template
- How to display posts from a certain category in a bootstrap 5 carousel loop with multiple items?
- Pin posts to top of custom loop
- Remove custom taxonamy slug with pagination
- Add Pagination in custom Blog page template
- Order archive custom posts by taxonomy term [duplicate]
- How to add pagination to a post loop in a custom BuddyPress tab
- How to prevent post to repeat on my loop?
- How to display data with pagaination on backend?
- Custom Post Type Pagination Not Working or Single Posts Displaying?
- 404 error Custom search results page for custom post types with friendly URL
- Load different template for CPT (in loop) in my plugin?
- How to loop custom post type posts by author?
- Paged within a custom content type template [duplicate]
- Loop through multiple custom taxonomy terms and display posts for a custom post type
- is_singular won’t call my functions?
- loop through custom post-type with two meta_keys
- Remove plugin’s custom post type archive page and single pages [closed]
- How to exclude certain portfolios from a loop
- Group search results by post type, but having a unique heading for each section?