Home Forums Add-ons Flexible Content Field Pre-Defined/Required Flexible Layouts Reply To: Pre-Defined/Required Flexible Layouts

  • What version of ACF are you using. I’m assuming Pro (V5) since you’re using flex fields. When defining a layout you can specify a minimum and a maximum number of the layout that must/can be created. Setting them both to 1 will make them required.

    Adding them as defaults on a new post is a little bit more difficult, but it is possible. You can use an acf/load_value filter You can test the current value and if it is exactly NULL this means that the value has not been created yet and it is a new post. You can then return a value for the flex field that includes a set of layouts to appear automatically on the new post. To see what you need to return, create an acf/load_value filter for the field and then output the current value. I don’t know the exact setup for a flex field value but you can always see what you need to return by looking at what’s already a value in any ACF field type.

    add_filter('acf/load_value/name=YOUR_FIELD_NAME', 'YOUR_FUNCTION_NAME', 10, 3);
    function YOUR_FUNCTION_NAME($value, $post_id, $field) {
      echo '<pre>'; print_r($value); echo '</pre>';
      return $value;