1

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.

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.

1
  • Still looking for an answer that helps me figure this out. Anyone?
    – Eckstein
    Commented Dec 21, 2012 at 4:25

3 Answers 3

2

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' )
)
1
  • Thank you. I made that change, but it still doesn't seem like the field is being saved, or something else weird... I'm using this little validation code to make sure the user has entered content, and with the editor in place, it keeps saying there is nothing there (even when there is). if(empty($_REQUEST['user_post_content'])){ $error_flag = TRUE; $error_msg[]=array( 'key' => 'error_user_post_content', 'value' => __('Please enter some content','tsv'), ); }
    – Eckstein
    Commented Dec 20, 2012 at 8:22
1

I was working on same kind of project and find this jquery plugin useful

http://jhtmlarea.codeplex.com/

Regards

1
  • Thanks. I want to use TinyMCE though so that the behavior is as close as possible to the admin side, including the media uploader.
    – Eckstein
    Commented Dec 20, 2012 at 23:21
1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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