我试图在页面和帖子中制作自定义元框... 我确实有滑块标题和内容,我需要在这些特定的帖子和页面上。 我确实在输入框中保存了标题部分的值。 在内容部分,我使用了Textarea,我的价值根本没有出现..
代码:
<?php function xgr_settings() {
add_meta_box(
'extra-slider-settings', // $id
__( 'Extra Slider Settings', 'xgr' ), // $title
'xgr_add_slider_options_callback',// $callback
array('post','page'),
'normal', // $context
'high' // $priority
);
}
add_action( 'add_meta_boxes', 'xgr_settings' );
$xgr_settings = array(
'slider-heading' => array(
'name' => __('Slider Heading','xgr'),
'value' => 'slider-heading',
'id' => 'slider-heading'
),
'slider-content' => array(
'name' => __('Slider Content','xgr'),
'value' => 'slider-content',
'id' => 'slider-content'
),
);
function xgr_add_slider_options_callback($post){
global $post , $xgr_settings;
?>
<div class="metabox">
<div class="row">
<?php foreach($xgr_settings as $field) {
$headings= get_post_meta($post->ID,$field['id'],true);
var_dump($headings);
?>
<?php if(($field['id']) === 'slider-heading') { ?>
<div class="form-group">
<label style="margin-bottom: 9px; font-style: italic; padding: 15px 10px; line-height: 1.3; vertical-align: middle;" class="control-label f13" for="inputDefault"><?php echo esc_attr( $field['name'] ); ?></label>
<input style="width:100%" type="text" class="form-control" id="<?php echo esc_attr( $field['id'] ); ?>" name="<?php echo esc_attr( $field['value'] ); ?>" value="<?php echo $headings ? $headings : '' ?>">
</div>
<?php
} elseif(($field['id']) === 'slider-content'){ ?>
<div class="form-group">
<label style="margin-bottom: 9px; font-style: italic; padding: 15px 10px; line-height: 1.3; vertical-align: middle;" class="control-label f13" for="inputDefault"><?php echo esc_attr( $field['name'] ); ?></label>
<textarea style="width:100%;min-height:200px;" type="textarea" class="form-control" id="<?php echo esc_attr( $field['id'] ); ?>" name="<?php echo esc_attr( $field['value'] ); ?>" value="<?php echo $headings ? $headings : '' ?>"></textarea>
</div>
<?php } } ?>
<br>
</div>
</div>
<?php
wp_nonce_field( 'xgr_nonce', 'xgr_nonce' );
}
function xgr_save_funtions($post_id){
$heading = sanitize_text_field( $_POST['slider-heading']);
$content = sanitize_text_field( $_POST['slider-content']);
if(isset($POST['xgr_nonce']) && wp_verify_nonce( $POST['xgr_nonce'], 'xgr_nonce')){
return;
}
if(isset($_POST['slider-heading'])){
update_post_meta($post_id ,'slider-heading',$heading);
}
if(isset($_POST['slider-content'])){
update_post_meta($post_id ,'slider-content',$content);
}
}
add_action('save_post','xgr_save_funtions');
答案 0 :(得分:2)
TextArea标签没有值=&#34;&#34;参数
使用:
<textarea>{YOUR VALUE TO SHOW}</textarea>
<textarea style="width:100%;min-height:200px;" type="textarea" class="form-control" id="<?php echo esc_attr( $field['id'] ); ?>" name="<?php echo esc_attr( $field['value'] ); ?>" ><?php echo $headings ? $headings : '' ?></textarea>