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
- Create an archive page by combining two post type
- author archives, showing all custom post types, problem on pagination
- WordPress Custom Post Type Archive, filter by category and get pagination working
- Custom Post Type has wrong label and is not found when called by a loop
- Some posts not displaying by taxonomy term
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- Add Pagination in custom Blog page template
- Problems in paginate_links with custom query loop and MB-Relationships
- Why do my custom post type show up in all pages?
- How to create an IF statement in the Main Loop for Custom Post Types
- Combine multiple separate lists into one
- Custom post type, next and previous links by page title
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- How to show custom post count in archive page
- Error in the page of a CPT file in WordPress
- ACF meta_key and meta_value break loop
- How to output and alert message when updating a post
- Do not show child pages within a file page
- Display all posts from specific category and CPT
- Looping to organize and display custom posts by category using PHP and WordPress
- WordPress custom post type taxonomy paging
- Custom post types not showing on the standard WordPress Category page
- Tell wordpress to show a single page instead of an archive page
- Permalink for custom post type pages not working
- WordPress doesn’t respect Page slug in custom post type url pagination. Keeps getting removed
- How to display custom post type pagination buttons when processing AJAX request
- post_type incorrect for custom post type
- Loop (for search results) returning right posts, but wrong post type
- Skip latest 3 posts from loop
- Pagination for a cpt filtered with a category
- Archive for custom taxonomy
- Make pagination work as a carousel (custom query)
- Custom Post Type archive page listing a 404 or single post
- posts_per_page is not working by term
- Staggering featured post using ‘sticky’
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Turning archive templates to a page template maintaining the slug
- My post loop needs to have 8 different post templates
- 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 categories giving 404
- List all posts associated under custom taxonomy
- How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta