When I stick a post in the backend, I want it to be added a meta_key
and meta_value
. In other words, to control the date when the post has been marked as sticky, I want to add a meta_key
like date
and a meta_value
like date( 'm/d/Y H:i:s')
.
I think it is possible with hook and add_action
, but I don't know how. Is there a way to do that?
Making a post sticky actually updates a blog option in WordPress background:
update_option('sticky_posts', $stickies); (see core in wp-includes/post.php)
So your hook could be pre_update_option_sticky_posts (prefix pre_update_option_ + name of the option), like this:
add_action( 'pre_update_option_sticky_posts', 'my_function' );
function my_function( $post_id ) {
Your code here to save the custom field values
}