Support

Account

Home Forums Add-ons Flexible Content Field Export / Import flexible field with shortcodes

Unread

Export / Import flexible field with shortcodes

  • For my custom coded theme I created a export / import functionality available on the page template that uses a flexible field.

    The whole thing works decently well and succeeds in exporting / importing complex pages built with the flexible field, that saves a lot of time when deploying content from (1) local to (2) dev and then to the (3) live sites.

    My biggest problems comes when I export fields containing shortcodes. I retrieve the ACF flexible field using the function get_field('content_rows', $page_id) and it already has converted the shortcodes to the resulting html. I also tried using get_field('content_rows', $page_id, $format_value = fase) and this one returns the right content, but does not return the names of the subfields, but their subfield codes (eg. field_68258f19060e1).

    The next solution I tried was to disable the shortcode functionality before calling the get_field('content_rows', $page_id) function. This worked partially: the shortcodes are not run, but all the quotes inside these shortcodes are converted to Unicode characters (UTF left quote / right quote). My final workaround was to do a string replace, replacing these UTF characters inside [] with the normal double quote character.

    While this solution does work at the moment, it seems really fragile. Is there any relatively simple way of getting the content of the fields as returned by get_field('content_rows', $page_id, $format_value = fase) but with the keys returned by get_field('content_rows', $page_id)?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.