This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
When working with WordPress, there are times when you need to clean the object term cache. The `clean_object_term_cache` action fires after this cache has been cleaned. Let’s dive into how you can use this hook in your WordPress projects.
clean_object_term_cache action
Fires after the object term cache has been cleaned.
To use the `clean_object_term_cache` action, you first need to register it using `add_action`. You can add this code to the `functions.php` file of your active theme or in a custom WordPress Plugin.
At WePlugins, we always prefer creating a custom WordPress Plugin for hooks to prevent any issues when updating your WordPress Theme in the future.
In the following live examples, we will define a function `weplugins_execute_on_clean_object_term_cache_event` which takes 2 parameters and register it using `add_action`. The first parameter `clean_object_term_cache` is the name of the hook, the second parameter `weplugins_execute_on_clean_object_term_cache_event` is the name of the function that needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed to the registered function.
Sometimes, you may need to remove a registered hook using `remove_action` to remove the `clean_object_term_cache` action.
Parameters
Below are the 2 parameters required to use this hook:
- $object_ids: (array) An array of object IDs.
- $object_type: (string) Object type.
Live Example 1
Here’s how you can use this hook:
function weplugins_execute_on_clean_object_term_cache_event($object_ids, $object_type){ // Code to be executed when this action occurs in WordPress. // Utilize the parameters received in the function arguments to implement your custom functionality. } // Add the action add_action("clean_object_term_cache", "weplugins_execute_on_clean_object_term_cache_event", 10, 2);
Live Example 2
To remove a hook callback, use the example below:
remove_action("clean_object_term_cache", "weplugins_execute_on_clean_object_term_cache_event", 10, 2);
Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Live Example 3
Another example showcasing the use of this hook:
function weplugins_another_clean_object_term_cache_event($object_ids, $object_type){ // Additional custom functionality } // Registering the hook with a different function add_action("clean_object_term_cache", "weplugins_another_clean_object_term_cache_event", 15, 2);
Contact Us
If you need any customization or are having trouble using this hook, feel free to contact our team. We’d be happy to assist you!
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.