Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track WordPress changes on post edit/save

Tags:

wordpress

I would like to know how to run a function when a meta information of a custom post type is changed.

For example, I have a radio box associated with a custom post type. And made it with metaboxes, and when I change the option, I would like to run a function.

How would I do that?

like image 748
Mike Avatar asked Mar 22 '26 13:03

Mike


1 Answers

Originally in OP's question.

I think I found what I wanted

function do_my_stuff($post_ID)  {
   //do my stuff here;
   return $post_ID;
}

add_action('save_post', 'do_my_stuff');

Wordpress: executing function when saving or editing post

But is it possible to track what changes were made?

Yup, did it with your help diggy, but had to change something.

function do_my_stuff($post_ID)  {
   $newvalue = $_POST['my_metabox_value'];
   echo $newvalue;
   $oldvalue= get_post_meta($post_id, 'my_metabox_value', true );
   echo $oldvalue;
}

add_action('pre_post_update', 'do_my_stuff');
like image 156
2 revsbrasofilo Avatar answered Mar 24 '26 01:03

2 revsbrasofilo