Interesting question. Wp_Query
will return all posts that match the criteria. To enhance performance, you can switch off pagination with no_found_rows=true
. You want both pagination and limit the amount of results returned. That’s not something wp_query
can deliver.
So the most obvious though not too elegant solution would be to modify your loop in the same way you modify your pagination to cut off the superfluous results:
while( $query->have_posts() ) {
if (($wp_query->current_post) =< 10 ) {
$query->the_post();
the_title();
}
}
An alternative way would be to use wpdb
and build your own mysql query. Or use no_found_rows
and build your own pagination for the results.
Related Posts:
- Multiple WP_Query loops with Pagination
- Pagination returns 404 after page 20
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- Pagination with 5 posts per page
- Pagination/infinite scroll with WP_Query and multiple loops
- Pagination Not working on Home Page with 2 Query
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- Transient pagination not working properly
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Woocommerce custom loop to show all the products [closed]
- How to bring specific post to front of wordpress loop?
- Pagination stops at page 6
- Paginated HTML Sitemap
- Multiple WP_Query loops with Pagination Not Working
- Posts loop with pagination on a single post page
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pagination is broken and I need help fixing it
- Storing query variable and then using wp_reset_query
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Five posts from a category in footer
- posts_per_page not working for first page of pagination
- How do I get my custom query to work with search results after the first page?
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Second loop pagination changes URL, not content
- I am officially missing something about transient posts
- Query Not working as expected
- Paginate pages with dynamic query
- Function the_posts_pagination() not compatible with WP_Query arguments
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Pagination inside the blog page not working
- Custom Query Pagination not working on static front page
- Paging works correctly on local version, but not live?
- Problem with custom WP_Query and underlying pagination/posts_per_page
- 2 Loops on one page – pagination of 2nd loop ignore array of excluded posts
- Pagination returns 404 after page 20
- custom query – offset to pagination
- Pagination not working with WP_QUERY
- No content found on page 2 of pagination with 1 post per page
- wp_query pagination links producing 404
- Loop being strainge
- Pagination in custom query not working [duplicate]
- Multiple loops on index page with sticky post and pagination
- Pagination problem with multiple loops on the same page
- Show number of posts AND number on current page (cannot make it work)
- Pagination only showed when no category is set in wp_query
- Multiple queries and pagination
- Pagination when using wp_query?
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Can I force WP_Query to return no results?
- Find out total number of pages in global query on archive page?
- Resetting post data to previous loop in nested loops
- Some doubts about how the main query and the custom query works in this custom theme?
- Post_count only shows the number of results per page
- Get post count of current loop when using multiple queries on one page
- Pagination with custom SQL query
- Using a custom WP_Query with get_template_part loop
- WordPress Pagination Not Working – Always Showing First Pages Content
- WP_Query vs get_posts
- Loop within a loop?
- WP_Query and next_posts_link
- get_query_var function not working at all
- Show posts without term
- get_query_var( ‘paged’ ) not working outside of homepage
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Display products from specific category in shop page
- Pagination on a WP_query not showing navigation links
- How to list some posts first in the loop based on post id
- Different ‘posts_per_page’ setting for first, and rest of the paginated pages?
- How to paginate wordpress [gallery] shortcode?
- paginate_links() adds empty href to first page and previous link
- Make loop display posts by alphabetical order
- WP_Query: query posts by ids from array?
- Use WP_Query with have_posts()?
- paginate_links ignore my format
- get custom post type by tag
- How to get order of posts?
- Order posts by ID in the given order
- Combining two wordpress queries with pagination is not working
- Custom WP_Query order by post_meta and (author) user_meta
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- get_template_part in for loop
- Get array of posts from the current archive page loop
- pre_get_posts with get_posts
- How to paginate attachments in a secondary query as gallery?
- How-to exclude terms from the main query the most performant way?
- Executing Queries in tag.php
- Display posts the match taxonomy term linked from wp_list_categoies?
- How can I save an array from a random post sequence for later use?
- WP_Query and Pagination on a Static front page
- How to place a loop within another loop?
- WordPress Custom Query to show posts from last x years
- next_posts_link not working for loop called with ajax
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- How to order posts tag by tag?
- Query Custom Meta Value with Increment
- “pre_get_posts” firing on every query
- Why does pagination always break when used on any form of a home page?
- Show two random posts from custom post type