advanced custom fields – ACF textfield replaced new lines in block with “rn”

Question

I use ACF 5.12 (WP 5.8.4) and have field groups defined for certain block types as per this guide.

All fields of type “Text Area” in the block mess up new line rendering and output strings, e.g. a var_dump() when outputting with get_field() will look like like “ThisrnHasrnLinernBreaks” with the \r\n line breaks neither replaced nor rendering properly.

The actual entry in the wp_posts table looks like this:

<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:acf/tile {
    "id": "block_61f257dffcbe7",
    "name": "acf\/tile",
    "data": {
        "font": 8477,
        "_font": "field_61dd8dbe42496",
        "label": "This\r\nHas\r\nLine\r\nBreaks",
        "_label": "field_62021c6f27181",
...

So it does save the line breaks correctly when entered in the backend, but get_field somehow transforms the value.

I’ve also tried get_field without formatting value, e.g. get_field('label', false, false) but no change. Also nl2br or similar on the return value will fail, since it already returns them with dropped backslashes.

The “New Lines – Controls how new lines are rendered” in the ACF field settings seems to have no effect.

Why does ACF drop the backslashes instead of rendering actual newlines for those TextFields and how can I make it retain them?

0
kontur 5 months 2022-03-23T08:42:46-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse