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.
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.
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):
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).
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!