This is my custom meta box, here text area showing html tags.i used tinymc textaea editor. and i try to use wp_editor also. but data not saving.if it saved, i don’t know how to call it.
please help me find solution –THANK YOU–
<?php
add_action("admin_init", "admin_init");
add_action('save_post', 'save_points');
function admin_init(){
add_meta_box("productInfo-meta", "Product Details", "product_meta_options", "product", "normal", "low");}
function product_meta_options(){
global $post;
$custom = get_post_custom($post->ID);
$category = $custom["category"][0];
$brand = $custom["brand"][0];
$features = $custom["features"][0];
$holds = $custom["holds"][0];
?>
<table>
<tr>
<td>Category
<td> <input type="text" size="100" name="category" value="<?php echo $category; ?>" /> </td>
</tr>
<tr>
<td>Brand
<td> <input type="text" size="100" name="brand" value="<?php echo $brand; ?>" />
</tr>
<tr>
<td>Features</td>
<td><textarea rows="20" cols="100" name="features"><?php echo $features; ?>
</tr>
<tr>
<td></td>
<td>
<?php wp_editor( $content, 'test_content', $settings = array('textarea_name'=>'test_content','textarea_rows'=>20) );?>
</td>
</tr>
<tr>
<td>Holds
<td><textarea rows="20" cols="100" name="holds"><?php echo $holds; ?></td>
</tr>
</table>
<?php
}
function save_points(){
global $post;
update_post_meta($post->ID, "category", $_POST["category"]);
update_post_meta($post->ID, "brand", $_POST["brand"]);
update_post_meta($post->ID, "features", $_POST["features"]);
update_post_meta($post->ID, "holds", $_POST["holds"]);
}?>
There are a number of things going wrong in your code. I had to install it to see them all.
First, You don’t want
global $post
.save_post
will pass the post ID. Add a parameter to your callback.Note: that only passes the post ID, not the whole post object. If you needed the whole object (which you don’t) you could request a second parameter.
Second, lines like this one–
$brand = $custom["brand"][0];
— are triggering notices. You should be checking for the key before trying to use it.Third, that solves potential problems with lines like this one–
<td><textarea rows="20" cols="100" name="features"><?php echo $features; ?>
— by setting the value that areecho
ing to something.Fourth, you have a number of unclosed
<td>
tags causing very broken markup.Fifth,
wp_editor
, possibly the default instance, does not seem to like manually createdtextarea
s. I don’t know of a workaround but maybe there is one. I would love to know if someone out there has a solution. In the meantime, usingwp_editor
for all of thetextarea
s seems to work.Sixth, see this answer for issues with doing what you are doing if using less than (it looks to me) WordPress 3.5.
Seventh, saving the keys as you are you going to have your meta fields show up in the default meta fields box as well. Save your fields with a leading underscore.
Eight, you weren’t saving your content from the
wp_editor
in your original code at all.Nine, you weren’t retrieving you post content either.
Ten, you are running this code for all post saves, not just for your custom post type.
Eleven, you probably want to check that you are not dealing with a post revision, as in this example from the Codex.
Twelve, you would really do well to sanitize your
POST
data before shoving it into the database.POST
data is not safe. Though you can’t see it in the URL is trivial to alter.Put that all together, except for the data validation which I will leave to you since this is a marathon answer already :