Created
March 16, 2012 18:59
-
-
Save Kevinlearynet/2051853 to your computer and use it in GitHub Desktop.
Migrating existing custom field values into a meta box created with the WordPress WP Alchemy Meta Box Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once( plugin_dir_path( __FILE__ ) . 'classes/MetaBox.php' ); | |
include_once( plugin_dir_path( __FILE__ ) . 'classes/MediaAccess.php' ); | |
$meta_boxname = new WPAlchemy_MetaBox( array( | |
'id' => '_boxname_meta', | |
'title' => 'Metabox Name', | |
'template' => plugin_dir_path( __FILE__ ) . 'meta-template.php', | |
'mode' => WPALCHEMY_MODE_EXTRACT, | |
) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="form-table custom-meta"> | |
<thead> | |
<tr> | |
<th colspan="2">Meta box description goes here.</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<th scope="row">Field Label</th> | |
<td> | |
<?php | |
$mb->the_field('field_name'); | |
// Get value from an existing custom field | |
$custom_field = $mb->prefix . str_replace( array($mb->id . '[', ']'), '', $mb->get_the_name() ); | |
$value = get_post_meta( $mb->current_post_id, $custom_field, TRUE ); | |
?> | |
<input type="text" name="<?php $mb->the_name(); ?>" value="<?php echo $value; ?>" /> | |
</td> | |
</tr> | |
</tbody> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment