3

Hi i am not very experienced with plugin development and i am using edited_{$taxonomy} | Hook and i want to get old term value before this update. It is returning new value but i want to get old value (before update) because i want to use this in some other function. Here is my code

function action_edit_taxonomy( $term_id, $tt_id ) {
$term = get_term($term_id);
print_r($term);
};  
add_action( "edited_um_user_tag", 'action_edit_taxonomy', 10, 6 );

I know about edit_{$taxonomy} | Hook but i want to use above mentioned hook. Is it possible to get old value of term with this hook?
I will really appreciate it if someone will be able to guide me about this.
Thank you!

3

You would need to use a hook before the term is updated, both edit_{$taxonomy} and edited_{$taxonomy} fire after, though you still may be able to use Term Cache I wouldn't consider it reliable. Maybe try using the wp_update_term_data hook instead which gives you the current term before it gets updated, and the data that will be updated. You'll need to manually check for your taxonomy but it should work:

/**
 * @param Array $update_data    - array( 'name' => 'New Term Name', 'description' => 'New Description' )
 * @param Integer $term_id      - The term ID to update
 * @param String $taxonomy      - The Taxonomy the term belongs to
 *
 * @return Array $update_data
 */
function wpse270998( $update_data, $term_id, $taxonomy ) {

    if( 'um_user_tag' !== $taxonomy ) {
        return $update_data;
    }

    $term = get_term( $term_id, $taxonomy );
    return $update_data;
}
add_filter( 'wp_update_term_data', 'wpse270998', 10, 3 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.