Litespeed API tag_add




Wordpress LScache Plugin: Litespeed API tag_add

Last Updated on: Wed, 15 Apr 2026 00:00:02
How do i use this API to add tags to an old posts? what action to hook on to? Ive tried added this LiteSpeed_Cache_API::tag_add([ Book.Red ]) to my template page but it doesnt work. I tested it to see if its working or not by using LiteSpeed_Cache_API::purge([ Book.Red ]) , since i dont know how to find the cache tag. I need to add this in bulks not just for one post. The page I need help with: https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:api#litespeed_cache_apitag_add_tag Hi @foundbutlost, after you added the tag, you should find on your HTML source code. Is that you enter a private cache session? LiteSpeed_Cache_API::tag_add is for adding a tag to public cache, if its an private cache, please use LiteSpeed_Cache_API::add_private I didnt see any of that. there is only this two line on my html source ` ` Anyway i dont think you get my point. I meant the public cache. I have 10 posts under same custom taxonomy called Book . now i want to add tag to all of these 10 posts so if i added a new post, i can automatically purge them by custom tag. it would be great if there is another parameter to pass the post id like `LiteSpeed_Cache_API::tag_add( [ Book.Red ], $post_id ) The tag will show when you enable debug. So apparently i cant see it while im logged in as admin. But still, its not working. The tags is not there. Can you please just give me a hint where i can use this API LiteSpeed_Cache_API::tag_add($tags) in order for it to work? Is it only possible to add tags when a post is published or updated? How do i add tags to an existing post without updating them one by one? Hi @foundbutlost, could you try to add the following code on your themes functions.php if ( is_tax( Book ) ) LiteSpeed_Cache_API::tag_add( Book.Red ) then purge the cache and check the page again. This code will add the tag on the page with taxonomy called Book if that page has been cached. Okay, its working now. The problem is i need to find a suitable action to hook on where i put the code. It will not works if i just put it straight to my single template file or function.php (without suitable hook). 2 more questions: 1. When i purged a post with a custom tags, i can see the custom tags would also got deleted. Did this behaviour correct? so i need to add the custom tag again every time after i purged the correlated post? 2. What is the characters allowance on the cache tag name? Is space allowed? because i see on the example and default tags it only uses period(.) as a delimiter. 1. Its correct, every time the post get cached need to apply the tag on it. 2. Since they are going to be used in a response header, tags must follow response-header rules. As such only ASCII characters are allowed, and no special characters (spaces, commas, quotes) may be used. Additionally, the public: prefix is reserved. For more details, please check on this section. Ah i thought api was the only way to add the cache tags. so apparently i can use this response header method too. i didnt see it, glad you pointed it out. Thank you so much for all the help :). Thread resolved.



LiteCache Rush: Speed comes from using less, not from doing it faster



Reference