The clear_global_post_cache() WordPress PHP function is a deprecated method used to clear the global post cache. It’s recommended to use clean_post_cache() instead.
Usage
To use this function, you simply need to pass the post ID to the function. For example:
clear_global_post_cache($post_id);
In this example, $post_id
is the ID of the post you wish to clear from the cache.
Parameters
- $post_id (int): The ID of the post you want to clear from the cache.
More information
See WordPress Developer Resources: clear_global_post_cache
The clear_global_post_cache() function was deprecated in WordPress version 3.5.0. It’s recommended to use clean_post_cache() instead.
Examples
Clearing Post Cache
If you have a post with an ID of 123, you can clear it from the cache like this:
$post_id = 123; // Post ID clear_global_post_cache($post_id);
This code will clear the cache of the post with the ID of 123.
Clearing Post Cache after an Update
After updating a post, you might want to clear the cache for that post:
$post_id = 456; // Post ID after update clear_global_post_cache($post_id);
This will clear the cache of the post with the ID of 456 after it has been updated.
Clearing Post Cache in a Loop
If you have a list of post IDs, you can loop through them to clear each one from the cache:
$post_ids = array(1, 2, 3, 4, 5); // Array of post IDs foreach ($post_ids as $post_id) { clear_global_post_cache($post_id); }
This code will clear the cache for each post ID in the array.
Clearing Post Cache after Deletion
After deleting a post, you might want to clear the cache for that post:
$post_id = 789; // Post ID after deletion clear_global_post_cache($post_id);
This will clear the cache of the post with the ID of 789 after it has been deleted.
Clearing Post Cache after Adding a New Post
When you add a new post, you might want to clear the cache for that post:
$post_id = 101112; // Post ID after adding a new post clear_global_post_cache($post_id);
This code will clear the cache for the newly added post with the ID of 101112.