I am new to creating meta boxes and I am trying to create a custom field meta box that is connected to a custom post type which is created by WooTheme Sensei (Post type = lesson). I am trying to use wp_editor, but the issue is I can't seem to get the field to save.
I have checked many similar questions here and Google a lot, trying different solutions but nothing seems to work, I must be missing something!
These are the 3 functions I am using, I tried to turn debugging on but nothing seems to stand out. Any help is appreciated!
add_action( 'add_meta_boxes', 'add_educadme_related_resources_metabox' );
add_action('save_post', 'save_educadme_related_resources', 10, 2);
// Add the Custom Fields Meta Boxe
function add_educadme_related_resources_metabox() {
add_meta_box('educadme_related_resources', 'Related Resources', 'display_educadme_related_resources', 'lesson', 'normal', 'high');
}
// The Custom Fields Meta Metabox
function display_educadme_related_resources() {
global $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-editor', array( 'textarea_name' => 'related_resources', 'media_buttons' => false ));
}
function save_educadme_related_resources(){
// Is the user allowed to edit the post or page?
global $post;
if ( !current_user_can( 'edit_post', $post->ID ))
return;
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// OK, authenticated: we need to find and save the data
update_post_meta($post->ID, "Related_Resources", $_POST["Related_Resources"]);
}