Skip to content

Commit 1e1e32c

Browse files
author
infinitnet
committed
fix: added category ID to cache key
1 parent 35b0e8d commit 1e1e32c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ For support, feature requests, or bug reports, please visit the [GitHub issues p
2828
Contributions to the plugin are welcome. Please fork the GitHub repository and submit a pull request.
2929

3030
## Changelog
31+
- **1.2**: Fix: cache key has to include category ID.
3132
- **1.1**: Transient caching logic and cache clearing improved.
3233
- **1.0**: Initial release.

relevant-recent-posts.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author URI: https://infinitnet.io/
77
* Plugin URI: https://github.com/infinitnet/relevant-recent-posts
88
* Update URI: https://github.com/infinitnet/relevant-recent-posts
9-
* Version: 1.1
9+
* Version: 1.2
1010
* License: GPLv3
1111
* Text Domain: relevant-recent-posts
1212
*/
@@ -65,6 +65,18 @@ function infinitnet_relevant_recent_posts_shortcode($atts) {
6565
$serialized_atts = serialize($relevant_atts);
6666

6767
$cache_key = "rrp_" . md5($serialized_atts);
68+
69+
if ($atts['scope'] === 'category') {
70+
$categories = get_the_category($post->ID);
71+
if (!empty($categories)) {
72+
$category_ids = array_map(function($category) {
73+
return $category->term_id;
74+
}, $categories);
75+
$args['category__in'] = $category_ids;
76+
77+
$cache_key .= '_' . implode('_', $category_ids);
78+
}
79+
}
6880

6981
$output = get_transient($cache_key);
7082

0 commit comments

Comments
 (0)