Home Forums Backend Issues (wp-admin) Textarea not pulling line break from database


Textarea not pulling line break from database

  • Hello,

    I have data with new lines stored in a custom field (_position_title):


    It displays fine on the front-end using explode:

    $position_titles =  explode( "\\n", get_field('position_title') );
    foreach ( $position_titles as $pt ):

    However, on the admin Edit Page, it does not convert the line breaks to new lines inside the textarea field that is for editing:


    I tried every valid value for new_lines but this seems to only apply to get_field() – not displaying the data in the admin textarea.

    		'key' => 'field__position_title',
    		'label' => 'Position Title',
    		'name' => '_position_title',
    		'type' => 'textarea',
    		'instructions' => '',
    		'required' => 0,
    		'conditional_logic' => 0,
    		'wrapper' => array(
    		    'width' => '',
    		    'class' => '',
    		    'id' => '',
    		'default_value' => '',
    		'placeholder' => '',
    		'maxlength' => '',
    		'rows' => '',
    		'new_lines' => '',
    		'readonly' => 0,
    		'disabled' => 0,

    Any idea why the WP admin custom field is not converting \n to new lines inside the textarea? I’m using ACF Pro 5.7.9 and WP 5.4.4.

  • I don’t understand where you are putting the new lines. Are you typing them into the field? Are they coming from somewhere else?

  • Hi John,

    The new lines come from either (a) the textarea custom field in WP admin Edit Page, or (b) added from WPAllImport custom fields (where contacts are imported from a CSV file):

    Screenshot of Edit Page:
    Screenshot of WPAllImport:

    I am not trying to put new lines on a front-end page anywhere. It is the back-end Edit Page where I want them converted to new lines inside the textarea for editing (first screenshot).

    Thank you.

  • Update: If I re-save the page, the new lines appear correctly in the textarea. I looked in the database and it appears new lines are stored as actual new lines rather than \n. (Screenshot of database: )

    So it looks like the real problem is with the way WP All Import is adding \n rather than a new line. I may need to separate these titles into 6 different fields if there is no way around this. Not an ACF problem after all.

  • I am not sure about the import, to add returns to a text field in php it would be "\r\n" note the double quotes so that PHP will interpret the string. I do not know what you need to get WPAI to insert the proper characters. I would contact them and ask, their support is usually pretty helpful.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.