php - Wordpress Post not getting updated in editor -
i building custom plugin 1 of project , facing issue custom fields have created, once trying save fields. not getting data displayed in admin editor. screenshot of issue page
i adding code below please find it.
<?php function apt_add_fields_metabox() { add_meta_box( 'apt_college_fields', __('college fields'), 'apt_college_fields_callback', 'college', 'normal', 'default' ); } add_action('add_meta_boxes','apt_add_fields_metabox'); //display fields metabox content function apt_college_fields_callback($post) { wp_nonce_field(basename(__file__),'wp_college_nonce'); $apt_college_stored_meta = get_post_meta($post->id); ?> <div class="wrap college-form"> <div class="form-group"> <label for="issue_check"><?php esc_html_e('issue date available','apt_domain'); ?></label> <select name="issue_check" id="issue_check"> <?php $option_value = array('yes','no'); foreach($option_value $key => $value) { if($value == $apt_college_stored_meta['issue_check'][0]) { ?> <option selected><?php echo $value; ?></option> <?php } else { ?> <option ><?php echo $value; ?></option> <?php } } ?> </select> </div> <div class="form-group"> <label for="college-details"><?php esc_html_e('college details','apt_domain'); ?></label> <?php $content = get_post_meta($post->id,'college-details',true); $editor = 'college-details'; $settings = array( 'textarea_rows' => 5, 'media_buttons' => true ); wp_editor($content,$editor,$settings); ?> </div> <div class="form-group"> <label for="application_date"><?php esc_html_e('application available date','apt_domain'); ?></label> <input type="date" name="application_date" id="application_date" value="<?php if(!empty($apt_college_stored_meta['application_date'])) echo esc_attr($apt_college_stored_meta['application_date'][0]); ?>" /> </div> </div> <?php } function apt_college_save($post_id) { $is_autosave = wp_is_post_autosave($post_id); $is_revision = wp_is_post_revision($post_id); if(isset($_request['wp_college_nonce']) && wp_verify_nonce($_request['wp_college_nonce'],basename(__file__))) { $is_valid_nonce = true; } else { $is_valid_nonce = false; } if($is_autosave || $is_revision || !$is_valid_nonce) { return; } if(isset($_request['issue_check'])) { update_post_meta($post_id,'issue_check',sanitize_text_field(['issue_check'])); } if(isset($_request['college-details'])) { update_post_meta($post_id,'college-details',sanitize_text_field(['college-details'])); } if(isset($_request['application_date'])) { update_post_meta($post_id,'application_date',sanitize_text_field(['application_date'])); } } add_action('save_post','apt_college_save'); ?>
there error code block.you missed out $_request['issue_check']
update_post_meta($post_id,'issue_check',sanitize_text_field(['issue_check']));
corrected code
update_post_meta($post_id,'issue_check',sanitize_text_field($_request['issue_check']));
Comments
Post a Comment