What you are doing here is on the Bad Ideas list. While you can replace the query in template that tends to break things, especially pagination.
In simplified form let’s say you have 10 testimonials and your WP settings are 5 posts per page:
- your template thinks there are 10 / 2 = 5 pages worth of testimonials
- but WordPress thinks there are only 10 / 5 = 2 pages!
So when URL instructs WP to show page 3… WP thinks there is nothing there. And this is just the one of obvious ways in which it breaks.
For any modificaiton of main loops you need to be using filter like pre_get_posts
and do it before template is even reached.
Related Posts:
- Pagination not working with custom loop
- Have different number of posts on first page
- wp_pagenavi() with custom wp_query()?
- Custom Post Type Pagination Not Working On Archive Page
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Archive page…limiting posts per page
- 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
- Fix custom query pagination without changing site-wide posts-per-page settings
- Pagination with custom post types results in 404 issues
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- How to display all posts from standard posts to custom post types in a loop with pagination?
- Paging doesn’t work?
- 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, Pagination and 404s?
- 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
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- 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?
- 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
- WPNavi pagination links not working on custom pages
- Query Multiple Post Types and Paginate Newly Created List
- Display Custom Taxonomy Alphabetically
- How To Show All Custom Post Types In A Category Instead Of Pagination?
- Full Custom Post Type List Organised by two Taxonomies
- Pagination issue on category.php using custom post type query
- Displaying Custom Posts on a Page
- Shortcode not working with post counter
- Problem: wp_query outputs all images on site
- Custom Post Type Pagination Paginates Only in URL Structure
- Get custom post type’s fields in a while loop as variables
- Is it possible to to use custom post type types on a page with the same slug somehow?
- WordPress custom post query with pagination
- Custom Post Type within the Loop on Homepage (Page Template)
- The loop seems stuck to a single (now deleted) post
- Posts per row on archive page (custom post type)
- How do I know the ‘meta_key’ for ordering my custom post type
- Next Post links not working in custom post type shortcode
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- Custom post type conditional in loop
- Listing all term items alphabetically / sorting loop
- can these 3 queries be re-written as 1 query?
- Custom post type pagination – always return first page
- Display related custom taxonomy posts in sidebar
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- How do I control the output of a custom post type in the loop?
- Display custom post type posts first, then default posts
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Three Most Recent Posts, One Per Term
- Targeting custom post type
- Does WP have a global of $id?
- WordPress Loop if/else
- Custom post type pagination 404
- get_the_title() is returning results from previous loop
- Custom Post Loop pulling all custom posts, not just one
- Conditional for a Single Post That Belongs to a Category?
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Custom Post Type single.php template only shows the latest post
- Sort posts in loop by the WooCommerce Membership of the author
- Pagination broken by naming conflict between CPT and Page
- Cant get paginations on single.php to work with my custom post types
- Including all post id’s of a custom post type into an array
- How to include custom post type posts on a page?
- 4 column-loop ordered alphabetically with entries grouped (and labeled) by their first letter
- Tag page only display 10 posts
- Number of posts in the archive
- Pagination custom post type not working with rewrite slug
- Pagination Not Working for Custom Taxonomy with Custom Query – 404 Error
- How can I group posts by months and years?
- get_post_type is always post
- Multiple Custom Post Type queries, how to DRY it up
- Custon Content within WordPress Loop
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Bootstrap accordion looping through posts incorrectly
- Main query not querying any posts in custom taxonomy template
- Loop increase number
- Custom post type showing same Post on all Pages
- Custom WP_Query always respond with 200 status even when no entry
- get_post_meta is not working inside shortcode
- Using wp_query to modify the loop in index.php for a CPT