Question

I have spent hours on this one. I want to add a rich text editor (ideally wp_editor) to the following custom post, but I cannot make it to work. It appears, but is not saving the information.

    public static function metabox_view($post, $params){

    wp_nonce_field(-1, 'slide_options_nonce');

    $values_array = get_post_meta($post->ID, 'slide_options', true);if(!is_array($values_array))$values_array=json_decode($values_array,true);

    foreach($params['args']['options'] as $option_id => $option){

        $option_multiple = isset($option['multiple'])?$option['multiple']:false;
        $option_value = is_array($values_array)&&array_key_exists($option_id,$values_array)?$values_array[$option_id]:($option_multiple?array():'');

        $option_value_default = isset($option['default'])?$option['default']:'';



        switch($option['type']){

            case 'line':
                echo '<fieldset class="tesla-option">';
                echo '<legend>';
                echo $option['title'];
                echo '</legend>';
                echo '<div class="tesla-option-container">';                    
                echo '<input type="text" name="'.$option_id.'" value="'.$option_value.'" placeholder="'.$option['description'].'" />'                   
                ;                           
                echo '</fieldset>';

                break;  

            case 'text':

                echo '<fieldset class="tesla-option">';
                echo '<legend>';
                echo $option['title'];                  
                echo '</legend>';
                echo '<div class="tesla-option-container">';                                                        
                echo $args = 


                '<textarea rows="1" cols="40" name="'.$option_id.'" placeholder="'.$option['description'].'">'.$option_value.'</textarea>';



                ;   
                echo '</div>';
                echo '</fieldset>'
Was it helpful?

Solution

You need to use the wp_editor function to replace your textarea with the wp wysiwyg editor.

<textarea rows="1" cols="40" name="'.$option_id.'" placeholder="'.$option['description'].'">'.$option_value.'</textarea>

Will become something like :

wp_editor( $option_value, $option_id, array('name'=>$option_id,'textarea_rows'=>1) );

More infos about wp_editor in the WP Codex

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top