我想你得把支票移走$location === header
然后使用以下命令保存元数据。
像这样:
//In your metabox before the fields
$location = get_post_meta( $post->ID, \'_est_template_location\', true );
if( empty( $location ) || $location != \'header\' ) :
$location = \'other\';
endif;
然后,在保存时,您已经解决了所有其他问题,这是一个简单的保存过程。
add_action( \'save_post\', \'clean_deactivated_theme_templates_post_meta\', 1, 2 );
function clean_deactivated_theme_templates_post_meta( $post_id, $post ) {
if( !current_user_can( \'edit_post\', $post_id ) ) {
return $post_id;
}
if( !isset( $_POST[\'theme_template_fields\'] ) || !wp_verify_nonce( $_POST[\'theme_template_fields\'], basename( __FILE__ ) ) ) {
return $post_id;
}
$theme_template_meta[\'_est_template_location\'] = esc_textarea( $_POST[\'_est_template_location\'] );
foreach( $theme_template_meta as $key => $value ) :
if( \'revision\' === $post->post_type ) {
return;
}
if( get_post_meta( $post_id, $key, false ) ) {
update_post_meta( $post_id, $key, $value );
} else {
add_post_meta( $post_id, $key, $value);
}
if( !$value ) {
delete_post_meta( $post_id, $key );
}
endforeach;
}