0

I'm building a plugin that uses custom posts. The custom post uses metaboxes but some of the meta fields need information typed in the post editor.

I'm trying to use post_content to retrieve whatever is in the post editor, but it's either empty, or it only returns what has been previously saved.

Is there anyway to retrieve the post content at anytime during the edit, without having to save the post first?

Thanks you in advance!

  • 1
    My wild guess here would be that you need to use JS, but I'm really not sure. Could you please edit your question to make it more clear what you require? – David Gard Jan 26 '15 at 15:53
  • David, I'm currently using $this->get_latest_content($post->ID). But that just gives me the last saved content in the post, not the latest in the post edit window. – user66595 Jan 27 '15 at 0:40
  • What is $this->get_latest_content()? I'd love to help, but if I cannot even see the code you are using, how can I? Another wild gues would be that you need to an event handler, which detects changes to your post content and then dynamically updates your metabox. – David Gard Jan 27 '15 at 10:49
0

All the rendered content of the page is available to the page. How would it be rendered otherwise?

jQuery('#content-textarea-clone').html()

gives you the current contents of the editor window, using jQuery. And

jQuery('textarea#content').html()

holds the initial content of the page (the saved one).

  • Andrei, yes that gives me the current, last saved content. If you keep typing in the content editor, the page is not updated. – user66595 Jan 27 '15 at 0:35
  • For instance the page contains: <div id="wp-content-editor-container" class="wp-editor-container"><textarea class="wp-editor-area" style="height: 300px" autocomplete="off" cols="40" name="content" id="content">Hello world. </textarea></div> – user66595 Jan 27 '15 at 0:36
  • The page above contains "hello world", but if you keep typing, the page content is not updated until you "save" the post. In my case I need to extract what's being typed in the editor, and neither jQuery('textarea#content').html() nor $this->get_latest_content($post->ID), provides that. – user66595 Jan 27 '15 at 0:39
  • Oops! You're right. Made a test and updated my answer. – tao Jan 27 '15 at 10:15

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.