我正在为我的某个项目构建一个自定义插件,我正在使用我创建的自定义字段来解决此问题,但是一旦我尝试保存字段。我没有收到管理编辑器中显示的数据。 screenshot of issue page
我在下面添加代码请找到它。
<?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 as $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');
?>
答案 0 :(得分:1)
您的代码块出错。您错过了$ _REQUEST [&#39; issue_check&#39;]
update_post_meta($post_id,'issue_check',sanitize_text_field(['issue_check']));
更正代码
update_post_meta($post_id,'issue_check',sanitize_text_field($_REQUEST['issue_check']));