Home › Forums › Backend Issues (wp-admin) › Textarea not pulling line break from database
Hello,
I have data with new lines stored in a custom field (_position_title):
Title1\nTitle2\nTitle3\nTitle4\nTitle5\nTitle6
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:
Title1\nTitle2\nTitle3\nTitle4\nTitle5\nTitle6
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.
array(
'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: https://ibb.co/ZGN4ZxT
Screenshot of WPAllImport: https://ibb.co/LvgNFtM
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: https://ibb.co/p2hRtMK )
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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.