2
votes

I have a custom post type for products. I have two TinyMCE editors (the standard and one for a summary field) loading correctly in the Dashboard. From the Dashboard side of things, everything is working correctly. Adds, updates. etc...

On the site though, output is loosing the line breaks (paragraph tags). Here is an example:

http://keg.brettatkin.com/products/complete-consulting-skills-learning-system/

I'm using the wp_editor function for this. (http://codex.wordpress.org/Function_Reference/wp_editor)

Here is my code:

<?php
function keg_product_fields (){
global $post;
$custom = get_post_custom($post->ID);
$keg_product_price = $custom["keg_product_price"][0];
$keg_product_link = $custom["keg_product_link"][0];
$keg_product_type = $custom["keg_product_type"][0];
$keg_product_featured = $custom["keg_product_featured"][0];
$keg_product_summary = $custom["keg_product_summary"][0];
$editor_id = "kegprodsummary"
?>
<p>
<label>Summary:</label><br />
<?php wp_editor( $keg_product_summary, $editor_id, $settings = array('textarea_name' => 'keg_product_summary') ); ?>
</p>
<p>
<label>Price:</label><br />
<input size="10" name="keg_product_price" value="<?php echo $keg_product_price; ?>" />
</p>
<p>
<label>Type:</label><br />
<select name="keg_product_type">
<option value="<?php echo $keg_product_type; ?>" selected="selected"><?php echo $keg_product_type; ?></option>
<option value="Book">Book</option>
<option value="CD">CD</option>
<option value="Downloadable">Downloadable</option>
<option value="Multimedia">Multimedia</option>
<option value="Virtual">Virtual</option>
</select>
</p>
<p>
<label>Link:</label><br />
<input size="65" maxlength="200" name="keg_product_link" value="<?php echo $keg_product_link; ?>" />
</p>
<p>
<input type="checkbox" name="keg_product_featured" value="Yes" <?php if (!(strcmp("$keg_product_featured","Yes"))) {echo "checked=\"checked\"";} ?>/>
<label>Featured Product</label>
</p>

<?php
}

function add_keg_product_box (){
add_meta_box(
"keg_product_info",
"Product Details",
"keg_product_fields",
"keg_products"
);
}


function save_keg_product_attributes ( $post_id )
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
return $post_id;
}

global $post;
update_post_meta($post->ID, "keg_product_price", $_POST["keg_product_price"]);
update_post_meta($post->ID, "keg_product_link", $_POST["keg_product_link"]);
update_post_meta($post->ID, "keg_product_type", $_POST["keg_product_type"]);
update_post_meta($post->ID, "keg_product_featured", $_POST["keg_product_featured"]);
update_post_meta($post->ID, "keg_product_summary", $_POST["keg_product_summary"]);

}

add_action ('admin_init', 'add_keg_product_box' );
add_action ('save_post', 'save_keg_product_attributes');
add_action ('publish_post', 'save_keg_product_attributes');
?>

Any ideas here?

Thanks!

Brett

2
i cannot see any tinymce editor at that pageThariama
I'm sorry, that page is an example of the paragraph tags getting stripped. It is saving bolds and such.Brett
if tags are getting stripped you might need t adjust the default setting of valid_elements and valid_children : tinymce.com/wiki.php/Configuration:valid_childrenThariama
add this to your functions file before the custom post code - wp_tiny_mce( false, array('remove_linebreaks' => 'false','convert_newlines_to_brs' => 'true'));ss888

2 Answers

1
votes

You have to apply the output filters with the apply_filters function in the page where you want to display your summary.

Example:

<?php 
$summary = get_post_meta(...);
echo apply_filters('the_content', $summary);
?>
0
votes

Try using wpautop() when saving the content or when showing it (I recommend you to use it when saving, for performance).
This function adds paragraphs throughout the text depending on the line breaks.