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.
So you’re diving into the world of WordPress hooks, eh? It’s like adding extra masala to your WordPress site, just the way we like our food with a bit of extra spice! Today, we’re going to talk about the added_term_relationship action. This hook fires right after an object-term relationship is added. It’s a neat way to add functionality without touching the core files. Let’s take a closer look at how we can use this hook effectively.
Example 1: Basic Hook Registration
In this example, we’re registering the added_term_relationship action using add_action. It’s like telling WordPress, “Hey, when this event happens, run this function.”
function weplugins_execute_on_added_term_relationship_event($object_id, $tt_id, $taxonomy){ // Code to be executed when the event occurs } // add the action add_action( "added_term_relationship", "weplugins_execute_on_added_term_relationship_event", 10, 3);
Example 2: Removing a Hook
Sometimes, you might need to remove a hook. It’s like saying, “I’m done with this task, no need to run it anymore.”
remove_action( "added_term_relationship", "weplugins_execute_on_added_term_relationship_event", 10, 3 );
Ensure you provide the same callback function name, priority, and number of arguments while removing the hook callback.
Example 3: Custom Functionality
Here’s how you can implement custom functionality using the parameters received by the hook.
function weplugins_custom_functionality_on_added_term_relationship($object_id, $tt_id, $taxonomy){ // Custom code here using $object_id, $tt_id, and $taxonomy } add_action( "added_term_relationship", "weplugins_custom_functionality_on_added_term_relationship", 10, 3);
The parameters for this hook include:
- $object_id: (int) Object ID.
- $tt_id: (int) Term taxonomy ID.
- $taxonomy: (string) Taxonomy slug.
Need help customizing your WordPress site? Contact Us for expert assistance!
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.