1

I have text-areas dynamically populated in the admin section of my custom post type.

             <div class="media_div">
                <span>Media</span>
                <input type="text"
                    class="meta_media"
                    name="media_desc[]"
                    value=""
                />
            </div>  

I then loop through the $_POSTS when saving the meta values, hence using [] in the name. The codex says only lowercase and _ can be passed to wp-editor.

How can I use wp-editor for these dynamically generated text areas?

wp_editor($ID, 'media_desc[]');
1

The second parameter to wp_editor is the value that the "id" attribute of the textarea element will have, and that is probably why there are such restrictions on it. By default it is also used for the "name" attribute but you can set it explicitly by using the $settings parameter to wp_editor

wp_editor($ID, 'media_desc_n',array('textarea_name' => 'media_desc[n]'));

  • Where does this code go? Before or after the text area code? I seem to be generating the MCE editors with correct ids and names but they are not replacing the text-areas, just showing above them... – myol Dec 16 '14 at 19:15
  • @myol wp_editor generates the testarea by itself, you don't need to add an explicit one. – Mark Kaplun Dec 16 '14 at 19:28
  • Ahh that makes sense. However, my textarea was output in sequence using $out .= so now the TinyMCE editor is out of the flow. I tried $out .= wp_editor(... – myol Dec 16 '14 at 19:33
  • you can use ob_start and ob_end_clean to get the output of wp_editor into a string – Mark Kaplun Dec 16 '14 at 19:37
  • 1
    not exactly the same, but the accepted answer is an example how you can convert an output into a string stackoverflow.com/questions/10144222/… – Mark Kaplun Dec 16 '14 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.