- This topic is empty.
-
AuthorPosts
-
July 12, 2011 at 7:28 pm #33466TheDocMember
I cannot, for the life of me, figure this one out. Every tutorial on the planet is the most convoluted and complicated thing I’ve ever read.
What I am trying to do sounds simple in principle, but is proving to be a time-vortex.
Goal: Have a second editable text area while editing a page in WordPress that utilizes TinyMCE.
Adding a simple textarea is easy, it’s adding the TinyMCE part that seems to have me stumped.
There are some plugins out there, but they are either too bloated or have stopped functioning properly. I feel like this is something that people must be utilizing all of the time while developing for WordPress – the only reason I haven’t done it before is poor documentation!
I got really close with this link: http://www.ilovecolors.com.ar/tinymce-plugin-textarea-metaboxes-wordpress/comment-page-1/#comment-8414
But the details that would help me implement it are missing. Any help would be greatly appreciated!
July 13, 2011 at 1:26 pm #83242TheDocMemberI absolutely poured hours into this and finally, after much frustration, have a working system. This is what goes in functions.php:
$prefix = 'dbt_';
$meta_box = array(
'id' => 'my-meta-box',
'title' => 'Related Links',
'page' => 'page',
'context' => 'normal',
'priority' => 'high',
'fields' => array (
array(
'name' => 'Textarea',
'desc' => 'Enter big text here',
'id' => $prefix . 'textarea',
'type' => 'textarea',
'std' => 'Default value 2'
),
)
);
add_action('admin_menu', 'mytheme_add_box');
// Add meta box
function mytheme_add_box() {
global $meta_box;
add_meta_box($meta_box, $meta_box, 'mytheme_show_box', $meta_box, $meta_box, $meta_box);
}
// Callback function to show fields in meta box
function mytheme_show_box() {
global $meta_box, $post;
// Use nonce for verification
echo '';
foreach ($meta_box as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field, true);
echo '', '
', $field;
}
}
add_action('save_post', 'mytheme_save_data');
// Save data from meta box
function mytheme_save_data($post_id) {
global $meta_box;
// verify nonce
if (!wp_verify_nonce($_POST, basename(__FILE__))) {
return $post_id;
}
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// check permissions
if ('page' == $_POST) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($meta_box as $field) {
$old = get_post_meta($post_id, $field, true);
$new = $_POST[$field];
if ($new && $new != $old) {
update_post_meta($post_id, $field, $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field, $old);
}
}
}
?>And this is what I use to call it on the page:
$meta = get_post_meta(get_the_ID(), 'dbt_textarea', true);
echo $meta; // if you want to show
?>July 13, 2011 at 1:32 pm #83236TheDocMemberAnd here is the updated version of what I’m using: http://www.deluxeblogtips.com/2011/03/meta-box-script-update-v30.html
July 13, 2011 at 1:40 pm #83237jacorreParticipantGood to know thanks!
January 8, 2012 at 2:01 pm #94288borantulaMemberin wordpress 3.3 version wp_editor function is added to save us from these headaches. for your information
Here is the link -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.