Replacing textarea with wp_editor

I have a working front end posting system on my site that initially I designed with a simple text area for the content. I am now attempting to swap the textarea out with the TinyMCE function, wp_editor. I can easily get the editor to display and function properly, but on the submission of the form, the content is saved/not saved in a strange way.

The behavior is as follows:
When I attempt to publish the post the first time, the content does not seem to save, leaving the textarea blank.
If I edit the post and save it again, the OLD content (from the first save) magically reappears and the new stuff is gone. After that, it randomly gives me either nothing or the old content only.

Read More

I’ve looked around, but was only able to find this question: wp_editor textarea value not updating which doesn’t exactly apply to my situation and I’m not sure that any of those solutions are really what I need.

I’m not sure what code would be best to help troubleshoot, but here is my original text box:

<textarea name="user_post_content" id="user_post_content" placeholder="Enter your content..." class="inputwide"><?PHP echo ((!empty($post_obj->post_content))?$post_obj->post_content:''); ?></textarea>

And here is what I want to replace it with:

<?php wp_editor($post_obj->post_content, 'userpostcontent', 'textarea_name=user_post_content' ); ?>

Here is a pastebin of the entire page template file: http://pastebin.com/tncmQGDA

Hopefully someone can help.

Related posts

Leave a Reply

3 comments

  1. Check with a array for the settings – $settings (array) (optional) An array of arguments. – on the function wp_editor.

    wp_editor(
        $post_obj->post_content,
        'userpostcontent',
        array( 'textarea_name' => 'user_post_content' )
    )
    
  2. Well, I got it corrected. It looks like it was because my post form uses javascript for errors and confirmation messages. I finally go a hold of the original developer who made this for me and he added this:

       jQuery('#user_post_submit,#user_post_preview,#user_post_savedraft').click(function(){
            var req;
            jQuery('#user_post_content').val(tinyMCE.get('user_post_content_editor').getContent());
            switch(jQuery(this).attr('id')){
                case 'user_post_submit':
                    req='publish';
                    break;
                case 'user_post_savedraft':
                    req='save_draft';
                    break;
                case 'user_post_preview':
                    req='post_preview';
                    break;
    
            }
    

    Which made this function work correctly:

    wp_editor($content, 'user_post_content_editor');
    

    Seems so simply now that it’s done….

    Thanks for all your suggestions though!