feat(wpmc S3): Helpers::get_term_by_slug with per-request cache
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,4 +15,14 @@ final class Helpers
|
||||
self::$current_town_resolved = false;
|
||||
self::$term_cache = [];
|
||||
}
|
||||
|
||||
public static function get_term_by_slug(string $slug, string $taxonomy = 'town'): ?\WP_Term
|
||||
{
|
||||
$key = $taxonomy . '|' . $slug;
|
||||
if (array_key_exists($key, self::$term_cache)) {
|
||||
return self::$term_cache[$key];
|
||||
}
|
||||
$term = \get_term_by('slug', $slug, $taxonomy);
|
||||
return self::$term_cache[$key] = ($term instanceof \WP_Term) ? $term : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user