phpwordpressmeta-boxeswp-editor

Wordpress add wp_editor to custom_meta_box


Can please anyone help? I created custom meta boxes, two of them are in textarea. This is what i have:

array(
        'label'=> 'Ingredients',
        'desc'  => 'List of ingrediends',
        'id'    => $prefix.'ingrediends',
        'type'  => 'textarea'
    ),
        array(
        'label'=> 'Directions',
        'desc'  => 'Directions',
        'id'    => $prefix.'directions',
        'type'  => 'textarea'
    )

==========================

case 'textarea':
    echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
        <br /><span class="description">'.$field['desc'].'</span>';
break; 

How do i add wp_editor? I tried:

wp_editor( $content, 'recipe_directions', array( 'textarea_name' => 'recipe_directions', 'media_buttons' => false, 'tinymce' => array() ) );

But no luck. Can anyone help. The whole idea is to make regular textarea like rich text editor

Thanks for your help .... anyone:)


Solution

  • Rather late than never.....

    In your class init function (assuming it's a plugin class) add

    add_meta_box(
        'ingredients_box_id',
        __( 'Ingredients', $this->textdomain ),
        array($this,'ingredients_box_content'),
        'ingredients_box',
        'advanced',
        'high'
    );
    

    Then add the function to enable the wp_Editor

    function ingredients_box_content( $post )
    {
        wp_editor( $meta_biography, 'ingredients_box_text_id', array(
            'wpautop'       => true,
            'media_buttons' => false,
            'textarea_name' => 'ingredients_box_text',
            'textarea_rows' => 10,
            'teeny'         => true
        ) );
    }