I would like to remove some metadata if I save post with another metadata with custom post type in my plugin.. I tried to use init hook and iterate array from get_posts function but it doesn’t work and too I tried with save_post hook but it doesn’t work too..
Attaching action in my __construct function (in class with plugin functions):
add_action('save_post_survey', [$this, 'survey_start_type_validation']);
And here I trying to check if metadata exists and if yes, then delete the old:
function survey_start_type_validation($post_id)
{
$type_of_running = get_post_meta($post_id, 'spusteni_dotazovani');
if($type_of_running == 'manually_run') {
if(metadata_exists($post_id, 'datum_a_cas_planovaneho_spusteni')) {
delete_post_meta($post_id, 'datum_a_cas_planovaneho_spusteni');
}
} elseif($type_of_running == 'planned_run') {
if(metadata_exists($post_id, 'running_status')) {
delete_post_meta($post_id, 'running_status');
}
}
}
I can’t figure out what’s wrong with my code.. Can anyone advice me?