Home > front end >  Wordpress. How do get the past terms in save_updated hook
Wordpress. How do get the past terms in save_updated hook

Time:01-28

When an article is updated, I want to get the terms before the update.

I can get the terms after the change, but I cannot get the terms before the change.

Is it possible to get the terms before the update?

Have you a good solution?

I tried this.

function my_post_updated($post_id, $post_after, $post_before)
{

 // The modified terms will be retrieved.
 // Of course, post ID will not change..
 get_the_terms( $post_before->ID, 'taxsonomy_name'); 

}
add_action('post_updated', 'my_post_updated', 10, 3);

CodePudding user response:

you need to use a pre-update hook.

pre_post_update

function my_post_updated($post_id, $post_data)
{

 // The modified terms will be retrieved.
 // Of course, post ID will not change..
 get_the_terms( $post_id, 'taxsonomy_name'); 

}
add_action('pre_post_update', 'my_post_updated', 10, 2 );
  •  Tags:  
  • Related