Support

Account

Home Forums General Issues Add PHP generated fields in own layout to Flexible Content Field

Helping

Add PHP generated fields in own layout to Flexible Content Field

  • I have a flexible content field that is defined as follows. The layout value is empty:

    {
    "key": "field_6576a2f9f2147",
    "label": "Content",
    "name": "content",
    "type": "flexible_content",
    "layouts": {}
    }

    Now fields are created dynamically in PHP, which I would like to summarise in layouts and add to the flexible content field.

    I know that I can add a field to an existing group using the parent attribute of acf_add_local_field. But how can I add it to a Flexible Content field?

  • The best solution I have found so far is to manipulate the field after on load

    function fb_change_layouts( $field ){
        $field['layouts'] = …
        return $field;
    }
    
    add_filter( 'acf/load_field/key=field_6576a2f9f2147', 'fb_change_layouts');
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.