Support

Account

Home Forums ACF PRO acf add local field to flexible content Reply To: acf add local field to flexible content

  • Looking at the settings of existing fields, a sub field of a flex field has the following settings

    
    // this argument is the post ID of the flex field
    $field['parent'] = $parent_post_id;
    // I don't know if this can be the flex field key or it must be the post ID.
    
    // this argument is the key of the layout
    $field['parent_layout'] = $parent_layout_key;
    

    I’m not at all sure that you can add a field to a layout, it’s not really listed in the documentation https://www.advancedcustomfields.com/resources/register-fields-via-php/, but if you can then you’ll probably need to include these settings.

    You can see what the settings of any field type are by creating some examples and creating some acf/load_field filters and in the filter display the field settings. This usually helps me figure out what I can change or what I need to add. https://www.advancedcustomfields.com/resources/acfload_field/

    
    add_filter('acf/load_field/name=my_field_name', 'my_acf_load_field');
    function my_acf_load_field($field) {
      echo '<pre>'; print_r($field); echo '</pre>';
      return $field;
    }