Is there a way to have pre-defined/required layouts, that are already selected and not removable by the user?
In my example, I will let the user create their own payment form. I’m wanting to always require the “Name & Address block”, as well as the “Credit Card block”. The user should still be able to move these blocks around within the other fields that he/she is going to create.
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 https://www.advancedcustomfields.com/resources/acfload_value/. 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.
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future. https://t.co/HahJUCcyH4