“This code works” – but it doesn’t!
If you’re gonna cache paginated posts, you’ll need to store them chunked:
if ( ! $my_paged = absint( get_query_var( 'paged' ) ) )
$my_paged = 1;
if ( ! $my_query = get_transient( "recent_$paged" ) ) {
$my_query = new WP_Query( "cat=3&posts_per_page=5&paged=$my_paged" );
set_transient( "recent_$paged", $my_query, 60 * 60 );
}
Related Posts:
- Transient pagination not working properly
- I am officially missing something about transient posts
- Check the stored / cached WP_Query with transients on post change
- WP_Query vs get_posts
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- WP_Query: query posts by ids from array?
- pre_get_posts with get_posts
- Query Custom Meta Value with Increment
- Identify which loop you are hooking into; primary or secondary?
- Duplicate Queries
- Transient not working for custom loops
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- wp_transients | wp_object_cache VS SESSIONS & Cookies?
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Transient caching for wp query
- Undefined WP_Query::has_posts()?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- if/else on custom query gives 200 OK when condition not met?
- Minimize database queries to user tables?
- Order by empty custom field
- Check if loop has any categories?
- How to get list of posts from permalinks?
- How to cache wp_query with pagination using transients?
- Is_single() conditional tag returns null in query
- Include current post into loop
- Using Transients
- Should I reset $wp_query?
- How to filter query loop block with a search string from the query parameters
- Save large WP_Query to transient === false
- WP_Query & Duplicate entries
- how to show more than 1 post into three columns query
- Ordering Posts by parent category, name ascending
- WP_Query secondary query failing
- Set Transient on CPT
- Loop through multiple custom fields with increasing number
- meta_query dates from an array
- Pagination in WP query with transient API
- 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
- Multiple queries and pagination
- How to remove only the latest sticky post from the loop
- Expecting statement error from php loop using ACF plugin
- Loop 3 posts column wise and continue the loop into same columns
- Get specific ACF key and value from all posts – no access to DB
- mysql query order by
- How I can repeat 2 HTML templates in a WordPress Query?
- PHP – Loop custom post type categories within jQuery Tabs
- Check if a post has term inside loop
- How to create a widget like this?
- Notice thrown when creating numeric pagination on custom query
- wordpress udpate query not equal to
- How do I sort this custom list of sticky posts
- WP_Query with one category in args shows other categories
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Query only displays one page_id
- How to Order By Two Custom Fields?
- Display specific page (that is child) content on parent page
- Different Loop for tag pages?
- Write WP Query that selects posts that are part of the same two categories
- Ordering posts by custom field and grouped by month
- Pagination for custom loop on custom page template is not displaying anything
- Does putting queries within loops cause an issue on WordPress?
- Filtering by multiple conditions in the loop
- WP_User_Query orderby meta_val_num
- Hiding carousel indicators if there’s only one post
- Query Taxonomy By Page Title
- WP_Query custom order and pagination
- How to access $wp_query object from array of posts given by get_posts?
- Function using get_posts() with tax_query not working when called from functions.php
- Display all attached image of every post of custom post type and link to original post
- 2 queries with counters
- Get posts with no tags?
- wp-query, pull children of parent page
- relation OR instead of AND – Filtered term ID’s in loop
- Writing less unnecessary code with WordPress
- How to SQL query posts IDs by categories AND authors?
- Does query_posts have an effect on get_the_category?
- Second loop pagination changes URL, not content
- Unable to paginate a custom page query
- How to change the default post type over the loop?
- Include one page/post into query which is already returning posts
- Insert images into wordpress post with a query
- Query Not working as expected
- Why doesn’t my WP Meta Query return any results?
- Compare “Main” post ID to ID inside wp_query loop
- Offset WP_Query by negative 1
- WP_Query orderby random do not repeat infinite scroll – one loop
- Paginate pages with dynamic query
- WP_Query loop doen’t work with my custom taxonomy
- Advise on Templates for Custom Queries
- Search.php – return number of results but cannot loop through
- How do I get the content of a custom instance of WP_Query?
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Creating ‘posts page’ loop based on the page itself
- Why does apply_filters behave different inside and outside a loop?
- WordPress Queries Not Working?
- WP_Query meta compare must include ALL array values
- Determine if ID is page or post and query the ID