I have a situation where posts can be saved and users can be notified when a post is saved if the “Send alert” checkbox has been checked. I don’t want the checkbox to be saved as it needs to be checked only when you want an alert sent out. This allows the admin to save, edit, etc. without any difficulties.

So far, I have added the checkbox in the publish box for a post:

function createCustomField(){
  $post_id = get_the_ID();

  if(get_post_type($post_id) != 'jobs'){
    return;
  }

  $value = get_post_meta($post_id, '_send_alert', true);
  wp_nonce_field('send_alert_nonce_'.$post_id, 'send_alert_nonce');
  ?>
  <div class="misc-pub-section misc-pub-section-last">
      <label><input type="checkbox" value="1" name="_send_alert" /><?php _e('Send alerts', 'pmg'); ?></label>
  </div>
  <?php
}
add_action('post_submitbox_misc_actions', 'createCustomField');

And have the save_post hook setup as well which needs to check for the checkbox if it is checked or not and then send out alerts if it is.

function save_job_callback($post_id){
  global $post;

  if($checkbox){
    //send out alerts here   
  }
}
add_action('save_post','save_job_callback');

The question I have is – How do I access the value of the checkbox within the save_post hook?

Read more here: Accessing a checkbox value in the save_post hook in WordPress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: