You’re saving every query object for each category to the same transient. Because this happens fast and time frame is one day, you’re always getting the query object for the first category back. Make your transient name variable with the category, e.g. like this:
$query_category_posts = get_transient('cached_posts_' . $category );
Of course you then need to get the transient with the variable name.
Related Posts:
- Minimize database queries to user tables?
- Redirect to another page using contact form 7? [closed]
- Combine results of multiple WP_Query to resemble single WP_Query
- How do I turn these values from MYSQL into an array
- Related Posts Excluding Certain Categories
- Using multiple variables to assign categories to an array
- What code to use in an array to call the current sub-category?
- Inject post (from specific category) between posts in Loop
- How to query only for products with status “in stock” in WooCommerce? [closed]
- get_posts with multiple categories
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- ajax category filter
- How can I save an array from a random post sequence for later use?
- How to order category.php loop by ‘meta_value’?
- Sorting Posts by custom field
- WP Meta Query for some meta (array) values
- meta_query with array as value
- Show list of authors with latest post NOT older than a month
- WP Query with multiple categories – passing an array works?
- WP_query category__in not working, only pulls from first category
- How get posts from a subcategory of a category by name?
- Transient caching for wp query
- How add a custom posttype name using ACF field to a query post array
- Get image of latest post from taxonomies/categories
- WP Query for variable taxonomies
- WP_Query arguments to fetch custom post type posts which are in certain category?
- Get category name from custom loop and echo it once
- How do I reset this wp_list_categories query?
- How to get count of posts assigned to given category?
- How to show subcategories using loop?
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- Remove a specific category ID from related post
- How to use transient in this code for related post?
- Complex Category selection as per user input
- Store sticky post’s ids in a transient
- Five posts from a category in footer
- only delete post within query / for each statement (front end)
- How to get all unique categories for posts in loop?
- category query for pages not working
- How to list custom fields as headers and list all pages sharing that custom field under it?
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- Transient not behaving as expected
- Warning: Invalid argument supplied for foreach(). when creating a WP_query
- Check if loop has any categories?
- Inserting HTML to close and open divs in WP_Query loops
- Removing duplicate values between two wordpress queries
- Finding WordPress Posts assigned to multiple categories
- Assign custom parameter to each post in query
- Does meta_value (array) work with ‘orderby’?
- WordPress Custom Search Form Displaying Unexpected Results
- Use premade array as categories in wp_query?
- wp_query is showing posts from other categories
- Using Transients
- extract serialized array to use for wp-query
- How can I split my query result in 2 arrays?
- How to display a list of posts in same child category as current post
- How to exclude a category name from showing?
- Loop categories by recent post
- Order a WP_Query by meta value where the value is an array
- WP_Query with page_ids in arguments without a result
- Query using string from custom field as array value
- Category based on post id
- How can i show pagenavi in my author.php?
- I am officially missing something about transient posts
- Finding and removing duplicates within WP Arrays
- meta_query returning excluded result
- Related posts by current posts child category
- Filter products on category AND tag
- Counting instances of words in the results of a post query
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- How to use the Term Object from a custom select field in a query
- WP Query by 4 different taxonomies
- Trouble with serialized metadata
- Related categories order posts by category
- Display All Top Child Categories / Taxonomy
- Query post by Category and custom file (ACF)
- Combine multiple queries, array_unique returns nothing
- Repeat array inside array through while loop
- Display 3 levels of categories on page
- Filtering ‘Featured’ posts from a batch of category IDs
- Related Post by Tags Code
- Hi , i am trying to set the post for 24 hours and with it will be changed
- Help displaying related categories
- Cant get unique_array() work on get_the_category() foreach loop
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Show full category tree for a year with all post titles?
- query.php – multiple is_category functions
- How to get several fields from wp_query?
- How to sort a WP_Query array by post_name after an array_merge();
- WP Query posts__in not working with array
- Sort Posts with custom meta key by default which is currently set as optional
- wp_get_archive for category returning different URLs on different but similar sites
- Related posts with WP_Query
- how to use transient method?
- query_vars category_name only display one catgory out of multiple categories
- How do I have multiple metaqueries inside one wordpress query
- I want to place a post before all others from an ACF boleen field
- wp_query, calculate with two dates when ‘key’ is text format
- Pagination only showed when no category is set in wp_query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2