• Resolved HappyCloud

    (@happycloud)


    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?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    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);

    Thread Starter HappyCloud

    (@happycloud)

    $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?

    Moderator keesiemeijer

    (@keesiemeijer)

    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);

    Thread Starter HappyCloud

    (@happycloud)

    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”

    Moderator keesiemeijer

    (@keesiemeijer)

    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);

    https://codex.www.ads-software.com/Function_Reference/get_post_meta

    Thread Starter HappyCloud

    (@happycloud)

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Auto adding paragraphs to custom fields, only showing first letter’ is closed to new replies.