I'm using wp-editor in a simple plugin, but I'm having an issue where the first time I hit the submit button the content from it is blank in the database.
<?php
$editor_id = 'mycontent';
wp_editor($content, $editor_id );
?>
So I tried alerting the content using this:
if (j(".wp-content-wrap").hasClass("tmce-active")){
alert( tinyMCE.activeEditor.getContent());
}else{
alert( j('#mycontent').val());
}
and the first submit comes up empty. If I switch to the text version before I submit, it works.
What am I doing wrong here that prevents the submit from working?
Edit: Interestingly, if I do this:
wp_editor('test', $editor_id );
It works. If I do this:
wp_editor('', $editor_id );
It doesn't work again.
How do I get it to work if the $content
is initially blank?
I'm using wp-editor in a simple plugin, but I'm having an issue where the first time I hit the submit button the content from it is blank in the database.
<?php
$editor_id = 'mycontent';
wp_editor($content, $editor_id );
?>
So I tried alerting the content using this:
if (j(".wp-content-wrap").hasClass("tmce-active")){
alert( tinyMCE.activeEditor.getContent());
}else{
alert( j('#mycontent').val());
}
and the first submit comes up empty. If I switch to the text version before I submit, it works.
What am I doing wrong here that prevents the submit from working?
Edit: Interestingly, if I do this:
wp_editor('test', $editor_id );
It works. If I do this:
wp_editor('', $editor_id );
It doesn't work again.
How do I get it to work if the $content
is initially blank?
3 Answers
Reset to default 0I just had the same problem. the submit of content of the wp_editor works not at first-submit, but perfect on second submit. Another way: Click on the html-button, and then click on the "Vusual"-Button. I do it with this jquery-statements in my jquery-code to submit the form:
$("#post_content-tmce").click();
$("#post_content-html").click();
These 2 lines before the $.post-statement makes the content of the editor visible, and submit works.
While debugging same issue in wp_editor, I have found that this issue is related to tinyMCE where its text field does not updated if we try to submit form using ajax call.
A workaround for this is just call window.tinyMCE.triggerSave()
before doing ajax call something like this:
window.tinyMCE.triggerSave();
$.ajax({
//your ajax call
});
Ok I figured it out. From what I've found, I can't simply pull the data out with javascript, I need to submit it as a form. duh!
I was trying to extract the content from wp-editor via jquery, but simply doing via a form worked better.
function post_product(){
if(isset($_POST['plug_post_type']) && 'newPost' == $_POST['plug_post_type']){
$prod_details = array(
'title' => sanitize_text_field($_POST['post_title']),
'content' => $_POST['content'],
);
}
}
add_action( 'init', 'post_product' );