0

I have a simple foreach loop and am putting together a timeline app. I'm using gravity forms to create / edit posts on the front end and am looking for a solution for a button or trigger that can delete a posts custom field (key & value) on click.

Pretty broad but along the lines of:

  • target this post in foreach
  • find meta key 'key'
  • delete meta key 'key' and its value on click
0

For anyone else looking for guidance on how to do this, I created another custom field called event_status and by using the save_post action in wordpress set a condition that once this changes to then the run delete_post_meta action as follows:

function event_status_is_updated($post_id){
  if(get_post_meta($post_id,'event_status',true)=='not_complete'){
    delete_post_meta($post_id,'date_dun');
  }
 }
add_action('save_post_event','event_status_is_updated');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.