WordPress添加元框不保存值
我试图添加自定义元字段来保存一些值并显示在循环中。自定义字段显示在编辑栏上,但不保存任何值。我读了很多文章,但没有找到解决办法WordPress添加元框不保存值,wordpress,Wordpress,我试图添加自定义元字段来保存一些值并显示在循环中。自定义字段显示在编辑栏上,但不保存任何值。我读了很多文章,但没有找到解决办法 add_action( 'add_meta_boxes', 'add_atomic_score' ); function add_atomic_score() { add_meta_box( 'score', 'Atomic Score:', 'atomic_score', 'post', 'side', 'high' ); } function atomi
add_action( 'add_meta_boxes', 'add_atomic_score' );
function add_atomic_score()
{
add_meta_box( 'score', 'Atomic Score:', 'atomic_score', 'post', 'side', 'high' );
}
function atomic_score( $post ){
echo '<p>Enter Atomic Score Here: </p>';
$text = get_post_meta($post->ID, 'score', true);
?>
<label for="score">Atomic Score: </label>
<input type="text" name="score" id="score" value="<?php echo $text; ?>" />
<?php
}
add_action( 'save_post', 'atomic_reach_save' );
function atomic_reach_save( $post_id )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post' ) ) return;
if( isset( $_POST['score'] ) )
update_post_meta( $post_id, 'score', esc_attr( $_POST['score'] ) );
}
?>
add_动作('add_meta_box','add_atomic_score');
函数添加原子分数()
{
添加元框('score','Atomic score:','Atomic_score','post','side','high');
}
功能原子分数($post){
echo'在此处输入原子分数:;
$text=get\u post\u meta($post->ID,'score',true);
?>
原子分数:
您正在检查nonce,但代码中没有生成任何nonce…是的,我后来发现了,我在这里发布了它..谢谢:)