“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
- Finding the next 5 posts
- How to bring specific post to front of wordpress loop?
- Why execute the_post()?
- WP_Query Order by Specific Post ID First
- What is considered a default query for the request filter?
- $wpdb insert is not work
- Using one WP_Query object within the loop of another WP_Query object
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- How to query a custom post type with a taxonomy filter but display post type archive page?
- How to display 7 most recent days of posts?
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Set Transient does nothing
- Change query_posts to WP_Query in page but does not work
- Optional Meta Query
- Set conditional on template based on referring page slug
- posts_per_page not working for first page of pagination
- Search form not working with custom query?
- date_query seems to be ignored by wp_query
- Better wordpress attachment query than this
- How do I rewrite this loop as a new WP_Query style-loop?
- What is the best way (regarding performance) to set transients for logged in users?
- Posts in loop all show the same author when there are many authors
- Show a 404 error page if Public query variable’s value doesn’t exist?
- Multiple Rows in a using wp_query
- If have posts a week old, display, else display a different loop
- Create a page template for “top rated posts” but show full content and not just a list
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- How to add tax_query to $args with concatenation
- How to create a widget like this?
- Does query_posts have an effect on get_the_category?
- Second loop pagination changes URL, not content
- setting offset to category number in archive page
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Show custom content when loop or wp query reaches specific time?
- Loop through array of pages
- Ajax buttons not working properly in WooCommerce when using wc_get_template_part
- Query Posts | Combining multiple form inputs into query arguments to generate one filter result
- How to query 5 users in random who have published more than 10 posts
- How to show post title in content editor in backend?
- What is the best way to reset a search on a meta_key / meta_value?
- Problem with custom WP_Query and underlying pagination/posts_per_page
- View related categories in order of posts
- WP_Query with child element
- Using URL variables on a custom WP_Query
- Show posts in category
- Both WP_Query and get_posts returning 1 post
- Using WP_Query to re-query and sort results using a date?
- Custom post type archive organized by category
- wp_query display posts based on day
- Sorting Posts Based On Meta Value Using AJAX
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- custom query to get posts
- Loop being strainge
- Problem with WP_Query sort
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- Get author meta data with no published posts in author.php?
- Print post data inside loop using theme content template
- Custom query for certain post type OR another post type with a certain category