Custom field losing p tags on display

I have a Custom Post Type that has several custom fields. One of the fields is multi-line and includes text with p tags.

When I view this field in the visual editor the p tags are all there.

Read More

I suspect the issue is how I am displaying the data in a custom template.

This is the code that I am using in the template to pull this particular custom field

 <?php $key="story"; echo get_post_meta($post->ID, $key, true); ?>

Is it the get_post_meta that is stripping these tags or something else? If it is this what should I be using instead?

Thanks for any clues

Related posts

2 comments

  1. Add this to your functions.php file:

    add_filter( 'meta_content', 'wptexturize' );
    add_filter( 'meta_content', 'convert_smilies' );
    add_filter( 'meta_content', 'convert_chars' );
    add_filter( 'meta_content', 'wpautop' );
    add_filter( 'meta_content', 'shortcode_unautop' );
    add_filter( 'meta_content', 'prepend_attachment' );
    

    Then use this code to pull in the result:

    <?php $story_content = get_post_meta($post->ID, 'story', true); echo apply_filters('meta_content', $story_content); ?>
    
  2. Try this:

    $key="story";
    $content = get_post_meta($post->ID, $key, true);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    echo $content;
    

    This should get your custom field and apply filters (with p tags)

Comments are closed.