I am using the *_add_form_fields
action to add fields to a custom taxonomy. One of those fields is a wp_editor().
The problem I am facing is that when I output the WordPress editor on the page like so:
wp_editor('test', 'mydescription', array('textarea_name' => 'my_description'));
and then if I click in the editor on the page and change the default value from test
to something else
the $_POST['my_description']
variable is still set to test
Should I be adding an additional setting to my editor? Is there a reason why I cannot change the value of the textarea?
EDIT
Below is a very simple test case that shows this happening. Place this in your functions.php file and then create a new tag. The posted value for ‘my_description” will not change.
class Test{
function __construct() {
add_action('add_tag_form_fields', array($this, 'add_tag_form_fields'));
add_action('created_term', array($this, 'created_term'));
}
function add_tag_form_fields($tag){
if ( current_user_can( 'publish_posts' ) ): ?>
<div class="form-field">
<?php wp_editor('test', 'mydescription', array('textarea_name' => 'my_description')); ?>
</div>
<?php
}
function created_term($tag){
echo '<pre>';
print_r($_POST);
echo '</pre>';
die();
}
}
new Test();
EDIT
This ONLY happens when attaching to “created_term” action. If you attach to “edited_terms” it works as expected and I think this is a result of ajax being used on the create term page… I have updated the test code to show this.
tinyMCE
<textarea>
element is initially unseen by the used serialize function:You will need to call
tinyMCE.triggerSave()
to make it visible.Below is a simple snippet that should do the trick:
This in an external file, enqueued with
wp_enqueue_script()
; it worked for the test I’ve conducted.In your
edited_terms
function you need to save the value and in youradd_tag_form_fields
you need replace your
test
with the saved data.something like:
Now if you want a much easier way of adding extra fields of all types to your tags/categories or custom taxonomy edit forms without reinventing the wheel take a look at
TAX Meta Class
According to the codex for wp_editor the first argument should be the content. So rather than ‘test’ you should put
$_POST['my_description']
if that is what you would like the initial content to be.