How do I add a rich text box to a Custom Post Type in Dashboard?
I'm trying to add a custom post type for 'surgeons' unfortunately theres like 6 sections i need to add which need to be rich text and not plain text for images, etc. this is what i currently have.
I have all the plain text fields working fine but now i need to add all rich text ones.
Set up various structures on backend
function personal_meta() {
global $post;
$custom = get_post_custom($post->ID);
$email = $custom["email"][0];
$phone = $custom["phone"][0];
$address = $custom["address"][0];
$website = $custom["website"][0];
?>
<p><label>Email:</label><br />
<input type="text" name="email" value="<?php echo $email; ?>" /></p>
<p><label>Phone - with extension. i.e. (805) 555-2323 Ex开发者_StackOverflow社区t 234</label><br />
<input type="text" name="phone" value="<?php echo $phone; ?>" /></p>
<p><label>Address:</label><br />
<textarea cols="50" rows="4" name="address"><?php echo $address; ?></textarea></p>
<p><label>Website - BEGINNING WITH http://</label><br />
<input type="text" name="website" value="<?php echo $website; ?>" /></p>
<?php
}
heres the code to save it
add_action('save_post', 'save_details');
function save_details(){
global $post;
update_post_meta($post->ID, "email", $_POST["email"]);
update_post_meta($post->ID, "phone", $_POST["phone"]);
update_post_meta($post->ID, "address", $_POST["address"]);
update_post_meta($post->ID, "website", $_POST["website"]);
}
You need to add the class "theEditor" which will then add the tinyMCE editor to the textarea
:
<textarea class="theEditor" cols="50" rows="4" name="address">
<?php echo $address; ?>
</textarea>
However, that will strip out <p>
and <br>
tags (not any others) when saved.
To prevent stripping those tags, you will need to try something like this:
<textarea class="theEditor" cols="50" rows="4" name="address">
<?php echo wpautop(get_post_meta($post->ID, 'your text area', true)); ?>
</textarea>
i think you have to do deep works, as on update_metadata , wordpress uses sanitize_meta function, which sanitizes the meta value, and thus, you may get plain value.
精彩评论