Home Forums ACF PRO REST API wysiwyg returns stripped html


REST API wysiwyg returns stripped html

  • When I retrieve a wysiwyg field via the new REST API integration in ACF 5.11.1, the string returnted in JSON contains all html tags except <p> paragraphs.

    I’m using the repeater field together with the wysiwyg field.

    Has anyone a clue of what can I do to format correctly the output ?

  • Did you find a solution? Anyone?

    The API does not return <p> tags but line breaks.

    Confirmed with ACF 6.0.3

  • I don’t know the answer to this, I am just assuming.

    It appears that filters are not being applied to the content when you get it using rest api. ACF WYSIWYG fields depend on applying filters acf_the_content for formatting.

    Looking at the acf code I don’t see any reason why the content should not be formatted correctly, you might want to contact the developers.

    As a work-a-round you could add this by adding your own filter. There is an undocumented hook acf/rest/format_value_for_rest, this hook has all the standard variations similer to the acf/format_value hook

    return apply_filters( 'acf/rest/format_value_for_rest', $value_formatted, $post_id, $field, $value, $format );

    Looking into it more the way the field is formatted is based on an acf setting, "rest_api_format" and the default for this setting is “light”, and WYSIWYG fields are do not run through the standard format_value filters when set to light.

    So after all of what I said, the corrective action is to add a filter the changes this setting to “standard”. However, this will change how all values are filtered and may have undesired affects on other field types, so the value of other field types may not return what you are expecting. See this If you use a filter to change this setting then you’ll likely need to find a way to alter the setting only for specific field types, and I don’t see any way of doing that.

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

You must be logged in to reply to this topic.