我正在尝试创建一个编辑器元框,我一直在遵循其他类似问题中找到的技巧,但没有幸运地让元框保存并显示其内容。元框显示,但当我写入任何内容时,它不会被保存。请帮忙!我已经干了几个小时了,一点运气都没有。
这是我目前的代码:
add_action( \'add_meta_boxes\', \'add_educadme_related_resources_metabox\' );
// Add the Custom Fields Meta Boxe
function add_educadme_related_resources_metabox() {
add_meta_box(\'educadme_related_resources\', \'معلومات إضافية\', \'display_educadme_related_resources\', \'lesson\', \'normal\', \'high\');
}
// Display The Custom Fields Meta Metabox
function display_educadme_related_resources( $post ) {
// Get the resources data if its already been entered
$educadme_resources = get_post_meta($post->ID, \'related_resources\', true);
wp_editor( $educadme_resources, \'related_resources\');
}
add_action( \'save_post\', \'save_educadme_related_resources\' );
// Save Function
function save_educadme_related_resources( $post_id ){
// Is the user allowed to edit the post or page?
if ( !current_user_can( \'edit_post\', $post_id ))
return;
// check autosave
if (defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) {
return;
}
// If empty don\'t do anything (don\'t save)
$related_resources = get_post_meta($post_id, \'related_resources\', true);
if(!$related_resources OR $related_resources == \'\') return;
// OK, authenticated: we need to find and save the data
if ( isset ( $_POST[\'related_resources\'] ) ) {
update_post_meta( $post_id, \'related_resources\', $_POST[\'related_resources\'] );
}
}