Skip to main content

Forums

This topic contains 4 replies, has 0 voices, and was last updated by  TheDoc 7 years, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33466

    TheDoc
    Moderator

    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!

    #83242

    TheDoc
    Moderator

    I absolutely poured hours into this and finally, after much frustration, have a working system. This is what goes in functions.php:

    < ?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:

    < ?php
    $meta = get_post_meta(get_the_ID(), 'dbt_textarea', true);
    echo $meta; // if you want to show
    ?>
    #83236

    TheDoc
    Moderator

    And here is the updated version of what I’m using: http://www.deluxeblogtips.com/2011/03/meta-box-script-update-v30.html

    #83237

    jacorre
    Participant

    Good to know thanks!

    #94288

    borantula
    Member

    in wordpress 3.3 version wp_editor function is added to save us from these headaches. for your information
    Here is the link

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star