I've been trying this for ages. I have this textarea in my plugin, that I'd like to replace with wp_editor. wp_editor gets the data but doesn't set it when changes are made.

Here's my textarea (it save's the data precisely):

        <textarea id="im_description<?php echo $rowimages->id; ?>"                                                                         placeholder="<?php echo __( 'Description', 'portfolio-gallery' ); ?>"
              name="im_description<?php echo $rowimages->id; ?>"><?php echo 
esc_html( stripslashes( $rowimages->description ) ); ?></textarea>

Here's my editor code (displays the data, but doesn't update it when i change it in the editor):

<?php wp_editor( $rowimages->description, 'mysecondeditor'); ?>

This would be a great tutorial for people who'd like to use the editor in their plugins.

EDIT: switched to wp_editor, because the_editor was deprecated.

EDIT no. 2: Done this update function but it doesn't seem to work. What am I doing wrong?

<?php if( isset( $_POST[$editor_id] ) )
update_post_meta( $content, 'editor_id', wp_kses( $_POST['editor_id'], $allowed ) );?>

My textarea:

<textarea rows="20" autocomplete="off" cols="40" name="im_description10" id="im_description10">text</textarea>

WP_edit text

<textarea id="im_description10" placeholder="Description" name="im_description10" style="height: 122px;" aria-hidden="false">text</textarea>

WP_edit rich

<body id="tinymce" class="mce-content-body im_description10 locale-lt-lt mceContentBody webkit wp-editor html4-captions" data-id="im_description10" contenteditable="true"><p>text</p></body>

First of all the the_editor() function has been deprecated and it's advised to use the wp_editor() instead.

Just to explain how the value is being saved, your value in the textarea isn't being saved by the textarea element but instead and most likely by update_post_meta.

To replace your textarea with wp_editor, you can define it as below:

$content   = stripslashes( $rowimages->description );
$editor_id = "im_description" . $rowimages->id;

wp_editor( esc_html( $rowimages->description ), $editor_id );
  • I still can't get how to save it. I would say maybe it's some problem with id or sth like that, because the textarea is being saved, without any update post function – Lukas Baranauskas Jan 25 '17 at 17:14
  • The element name is usually used as the identifier in POST requests name="im_description<?php echo $rowimages->id; ?>". Can you verify you have the same value for the name attribute when you use your textarea and wp_editor – Tunji Jan 27 '17 at 5:32
  • Seems like it, I've updated the topic with textarea html code, wp_editor text&rich html codes. – Lukas Baranauskas Jan 30 '17 at 13:34
  • Strange thing that it does update if I write text in the textarea, which has the same id and name. – Lukas Baranauskas Feb 3 '17 at 21:54

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.