我创建了一个客户概要文件自定义帖子类型,并开始创建元框等供用户输入信息。虽然所有这些看起来都很好,但当我去保存自定义帖子时,没有任何内容发送到数据库。以下是我的功能
Meta Box
function add_meta_boxes() {
add_meta_box(
\'client-info\',
__( \'Client Information\', \'textdomain\' ),
\'meta_box_clientinfo_callback\',
\'clientprofile\',
\'normal\',
\'high\'
);
}
add_action( \'add_meta_boxes\', \'add_meta_boxes\' );
Client Info Meta Box Callback
function meta_box_clientinfo_callback( $post ) {
global $my_post_meta;
$my_post_meta = get_post_meta( $post->ID );
wp_nonce_field( plugin_basename( __FILE__ ), \'my-nonce\' );
?>
<p>Please enter in the information on the client whom you wish to feature in a case story.</p>
<p>
<label for="client-name"><?php _e( \'Client Name\', \'textdomain\' ); ?></label>
<input type="text" name="client-name" id="client-name" value="<?php field_value( \'client-name\' ); ?>" size="25" />
</p>
<p>
<label for="client-age"><?php _e( \'Client Age\', \'textdomain\' ); ?></label>
<input type="text" name="client-age" id="client-age" value="<?php field_value( \'client-age\' ); ?>" size="3" maxlength="3" />
</p>
<p>
<label for="client-gender"><?php _e( \'Client Gender\', \'textdomain\' ); ?></label>
<select id="client-gender" name="client-gender">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="Other">Other</option>
</select>
</p>
<?php
}
Save Post
function save_meta( $post_id ) {
// Verify Nonce
if ( ! isset( $_POST[\'my-nonce\'] ) || ! wp_verify_nonce( $_POST[\'my-nonce\'], basename( __FILE__ ) ) ) {
return;
}
if ( ! current_user_can( \'edit_post\', $post_id ) ) {
return;
}
if ( isset( $_REQUEST[\'client-name\'] ) ) {
update_post_meta( $post_id, \'_client_name\', sanitize_text_field( $_POST{\'client-name\'} ) );
}
}
add_action( \'save_post\'. \'save_meta\', 10, 2 );
Field_Value Function
function field_value( $field_id ) {
global $post_meta;
if ( isset ( $post_meta[$field_id] ) ) {
echo $post_meta[$field_id][0];
}
}
我错过了什么?我在线查看了几个示例以获取我现在拥有的代码,但当我在PHPMyAdmin中查看
wp_postmeta
Post ID的表,我只看到
_edit_last
和
_edit_lock
.