Forums

[resolved] Auto adding paragraphs to custom fields, only showing first letter (7 posts)

  1. HappyCloud
    Member
    Posted 11 months ago #

    So I'm trying to auto add paragraphs to my custom field using wpautop but the filter I am using only shows the first letter of the first paragraph (Twice for some reason).

    If anyone could help it would be a huge relief, it's been driving me crazy

    $my_meta = get_post_meta($post->ID,'welcome_message',TRUE);
    echo $my_meta['name'];
    echo wpautop( $my_meta['description'], 1 );

    I've been adding it into the page I want the custom field to appear on, am I doing that wrong perhaps?

  2. keesiemeijer
    moderator
    Posted 11 months ago #

    Is $my_meta an array?
    for testing try:

    echo '<pre>';
    print_r($my_meta);
    echo '</pre>';

    You can also use apply_filters to add paragraphs:

    apply_filters('the_content',$my_meta);
  3. HappyCloud
    Member
    Posted 11 months ago #

    $my_meta is the array to show my custom field of "welcome_message" I think.

    Sorry, I don't have a vast knowledge of bare bones PHP.

    Where would I apply the filter? Directly onto the code for my custom field?

  4. keesiemeijer
    moderator
    Posted 11 months ago #

    What where the values when you tested the array with the code above?

    If the third parameter of get_post_meta is set to true then the function will return a single result, as a string.

    Do you have three different custom fields? (welcome_message, name, description).

    Where would I apply the filter?

    Wherever you want it, but it must be a string.

    // in a variable
    $var = apply_filters('the_content',$my_meta);
    // echo
    echo apply_filters('the_content',$my_meta);
  5. HappyCloud
    Member
    Posted 11 months ago #

    Nothing came up with I rested the array.

    Do you have three different custom fields? (welcome_message, name, description).

    No, I only have "welcome_message"

  6. keesiemeijer
    moderator
    Posted 11 months ago #

    No, I only have "welcome_message"

    On what theme template file are you using this?

    And are you using this inside the loop?

    Do posts have the "welcome_message" custom field?
    This inside the loop should work if posts have that custom field

    $my_meta = get_post_meta($post->ID,'welcome_message',TRUE);
    echo apply_filters('the_content',$my_meta);

    http://codex.wordpress.org/Function_Reference/get_post_meta

  7. HappyCloud
    Member
    Posted 11 months ago #

    That worked perfectly, thank you so much. You've spared me a lot of stress

Reply

You must log in to post.

About this Topic