我已经创建了一个元框。代码为:
/**
* Add meta box
*
* @param post $post The post object
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes
*/
function portfolio_add_meta_boxes( $post ){
add_meta_box( \'portfolio_meta_box\', __( \'Company URLs\', \'portfolio\' ), \'portfolio_build_meta_box\', \'portfolio\', \'side\', \'low\' );
}
add_action( \'add_meta_boxes_portfolio\', \'portfolio_add_meta_boxes\' );
/**
* Build custom field meta box
*
* @param post $post The post object
*/
function portfolio_build_meta_box( $post ){
// make sure the form request comes from WordPress
wp_nonce_field( basename( __FILE__ ), \'portfolio_meta_box_nonce\' );
// retrieve the current value
$fbportfolio = get_post_meta( $post->ID, \'fbportfolio\', true );
$twportfolio = get_post_meta( $post->ID, \'twportfolio\', true );
$instportfolio = get_post_meta( $post->ID, \'instaportfolio\', true );
$linkinportfolio = get_post_meta( $post->ID, \'linkinportfolio\', true );
?>
<div class=\'inside\'>
<h3>Facebook</h3>
<p>
<input type="url" name="fbportfolio" value="<?php echo $fbportfolio; ?>">
</p>
</div>
<?php
}
/**
* Store custom field meta box data
*
* @param int $post_id The post ID.
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
*/
function portfolio_save_meta_box_data( $post_id ){
// store custom fields values
update_post_meta( get_the_ID(), \'fbportfolio\', $_POST[\'fbportfolio\'] );
}
add_action( \'save_post_food\', \'portfolio_save_meta_box_data\' );