Say you have 10 pages of posts, 10 posts per page. When you load the first page and the transient doesn’t yet exist, your query loads the first page (10 posts) and you put that in a transient.
Now you navigate to page 2, and check if the transient exists. it does (you set it on page 1), so you load that instead of running a new query. Except your transient still contains posts 1-10, not 11-20 which you’re supposed to see on page 2.
You need to set a unique transient key for each page of posts, something like:
set_transient( 'posts_' . get_query_var( 'paged' ) , $query, 60);
and then fetch them by page:
get_transient( 'posts_' . get_query_var( 'paged' ) );
Related Posts:
- Transient pagination not working properly
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Transient api Caches confused
- Multiple WP_Query loops with Pagination
- WP_Query vs get_posts
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Pagination returns 404 after page 20
- WP_Query: query posts by ids from array?
- Custom WP_Query order by post_meta and (author) user_meta
- pre_get_posts with get_posts
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- Query Custom Meta Value with Increment
- Pagination with 5 posts per page
- Identify which loop you are hooking into; primary or secondary?
- Pagination/infinite scroll with WP_Query and multiple loops
- Add and in the header while looping over custom query in page template
- 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
- 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?
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Pagination stops at page 6
- Paginated HTML Sitemap
- How to output different posts per page?
- Multiple WP_Query loops with Pagination Not Working
- Posts loop with pagination on a single post page
- Undefined WP_Query::has_posts()?
- if/else on custom query gives 200 OK when condition not met?
- Pagination is broken and I need help fixing it
- Minimize database queries to user tables?
- 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
- Order by empty custom field
- posts_per_page not working for first page of pagination
- Multisite pagination issue by multi query archive 404
- Check if loop has any categories?
- How to get list of posts from permalinks?
- How do I get my custom query to work with search results after the first page?
- How to cache wp_query with pagination using transients?
- Is_single() conditional tag returns null in query
- Include current post into loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Should I reset $wp_query?
- Yoast primary category query modification
- How to filter query loop block with a search string from the query parameters
- Notice thrown when creating numeric pagination on custom query
- WP_Query custom order and pagination
- Second loop pagination changes URL, not content
- Unable to paginate a custom page query
- Query Not working as expected
- Paginate pages with dynamic query
- Function the_posts_pagination() not compatible with WP_Query arguments
- Pagination of custom page with custom fields query
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Check the stored / cached WP_Query with transients on post change
- Pagination inside the blog page not working
- Why pagination is not working with tax_query param?
- Custom Query Pagination not working on static front page
- WP_Query & Duplicate entries
- Paging works correctly on local version, but not live?
- how to show more than 1 post into three columns query
- 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 pagination (Title, date and teaser)
- Ordering Posts by parent category, name ascending
- WP_Query secondary query failing
- custom query – offset to pagination
- Set Transient on CPT
- Pagination not working with WP_QUERY
- Pagination is not working on custom query inside a custom home page template
- Loop through multiple custom fields with increasing number
- Pagination in custom query in a category page
- Horizontally paginate through sets of blog posts?
- No content found on page 2 of pagination with 1 post per page
- meta_query dates from an array
- wp_query pagination links producing 404
- Loop being strainge
- Pagination in custom query not working [duplicate]
- Pagination in WP query with transient API
- Multiple loops on index page with sticky post and pagination
- Pagination problem with multiple loops on the same page
- WordPress Post Looping? [duplicate]
- how to use transient method?
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Show number of posts AND number on current page (cannot make it work)
- Search results stuck on page 1
- Pagination only showed when no category is set in wp_query
- WordPress Number of Posts Not Changing With posts_per_page
- Which custom query am I in and how can I access its properties & methods?
- How to get to a specific position in wp_query?
- Next / previous posts link doesn’t show up with Posts 2 Posts
- query by meta value then date and not empty meta value