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
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- Get Custom post with ID
- Include Custom Posts Type in Year/Month/Date Archive
- How to append element after thumbnail
- Display custom post on home page based on a metabox selection
- Custom Post Types and archives
- get_template_part() – post-meta not working?
- How to get “custom post type”-archive with working permalink to it?
- Custom post type, permalinks & pagination, going wrong
- Filter post by current 2 differents users id
- Custom template page with custom archives listing by user
- Root slug of taxonomy returning 404
- Custom loop with multiple taxonomy queries
- Display custom post type posts first, then default posts
- Custom post type posts don’t show in archive widget
- Archive for a Taxonomy of a Custom Post type
- Including all post id’s of a custom post type into an array
- Multiple Custom Post Type queries, how to DRY it up
- Return the name of the post type
- Custom wordpress loop
- posts_per_page in custom WP_Query does not override “Reading” settings?
- Custom Post Type Archive Page showing as 404
- SEARCH QUERIES – REVERSE OUTPUT
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Adding a Section for Visitors
- Show parent category and subcategory once in while loop
- Custom Post Type Pagination – not displaying posts
- How to build Custom Post Nav Menu inside of the Loop
- Loop to display parent categories in custom taxonomy
- Display related post content and custom field content
- Pagination functions won’t work
- pagination for a custom query
- Custom nav menu current item custom link problem
- How To Loop Through list with Custom Post Types
- Custom Post Type + Category archive
- archive-{custom_post_type}.php not getting recognized wordpress
- Posts without featured image using other post’s featured image
- Get result from Custom Field in Custom Post type
- Display results from two Custom Post Types in page template
- Custom post-type’s pagination not working in category.php
- WordPress custom post type post and category links 404
- Get Posts From A Certain Post Type In An ID Array
- Pagination not working
- CPT Archive Pagination – Page not found
- WordPress post objects in one parent post object