my plugin has a save_post hook used to save the custom fields. now I add a publish_slider hook used to change a checkbox’s status(slider
is a custom post type). but it doesn’t work properly.
the save_post
hook is as below
add_action('save_post', 'save_post_func', 10, 1);
function save_post_func($post_id) {
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if ( isset($_POST['action']) && $_POST['action'] == 'inline-save' )
return;
...
if(isset($_POST[$key])){
update_post_meta($post_id,$key,$_POST[$key]);
}
else{
if($field['type']=='checkbox'){
update_post_meta($post_id,$key,0);
}
}
this would set a default 0 to the checkbox when I save a new post and didn’t set the checkbox, this is no problem.
and the publish_slider
hook is as below
add_action('publish_slider', 'publish_slider_func', 10, 1);
function publish_slider_func($post_id) {
...
update_post_meta($post_id, 'closeSlider', '1');
}
I hope when I publish the slider post, the closeSlider
checkbox would be set to 1 automatically, but it wouldn’t.
if I delete the update_post_meta($post_id,$key,0);
in the first function, then the publish
hook works