I have a custom content type called cards.
I have 3 custom meta fields called:
my_cards_activity (select field type; options 0 and 1)
my_cards_user (select type; many options)
my_cards_datetime (text field type; yyyy-mm-dd hh:mm format)
When I press SAVE button I want to get the value of the my_cards_activity
field (value can be 0 or 1) and if the value is 0 then change my_cards_datetime
and my_cards_user
to empty value and only after the change save it all. If it is 1 then do nothing.
How to do such before save thing? How should my code in functions.php look like?
Use the hook
save_post
and put an if inside the function that do the save after the ‘normal’ save meta fields routine.If in your metabox have you setted a nonce field check for it before save.
See Codex for: