Home Forums Add-ons Flexible Content Field Flexible Content – How to auto show minimum required layout fields.


Flexible Content – How to auto show minimum required layout fields.

  • Hi. I am using the Flexible Content Field. Is there a specified method or what is the best way to go about auto loading “One Layout” on page load?

    As maybe a suggestion of improvement, this is what I was expecting when using this field but it doesn’t work this way from what I can tell.

    When settings the Flexible Content field to one minimum layout (or more), I was hoping that ACF would auto make that field appear.

    It doesn’t seem the most user savvy to require the user to to have to fill these field out but still have to populate the minimum requirement. I was expecting the minimum required layouts to be loaded already, ideally with the option to open or close each field as needed.

    To be more visual this is what I mean…

    I have a custom post type. When a user loads my custom post type I want these options to automatically appear. But as it is, the user STILL has to click the “add Context Settings” button, then click the option for “Context Settings”, then add options they actually want. I was expecting that the requirement of 1 would make the layout fields auto show instead of having to click those extra button step. Basically getting them started without having to do that since I already know what they would actually have to do. See screenshot below…


  • What layout would each row “automatically” use? Since every layout needs to be chosen to be added.

    ACF doesn’t have the ability to select the default layout for each row in a flex field, which it would need in order to auto populate a specific number of rows.

    This is probably possible using a an afc/load_value filter but it is a bit convoluted and complicated to do.

    the first thing you need to do is understand the values of these fields and the best way to do that is to see it. To do this

    add_filter('acf/load_value/name=YOU FLEX FIELD NAME HERE', 'NAME_OF_YOUR_FUNCTION', 20, 3);
    function NAME_OF_YOUR_FUNCTION($value, $post_id, $field) {
      return $value;

    with this filter in place you can set up your flex fields with the defaults you want and then save it. Then the filter will show you what you need to return from the filter. You also need to see what the value of the field is when there are no rows, I think it’s NULL, but I don’t remember exactly, but assuming that it is NULL

    add_filter('acf/load_value/name=YOU FLEX FIELD NAME HERE', 'NAME_OF_YOUR_FUNCTION', 20, 3);
    function NAME_OF_YOUR_FUNCTION($value, $post_id, $field) {
      if ($value !== NULL) {
        // if the value isn't empty
        // NULL or whatever an empty repeater has
        // then it was already save and you don't want to change it
        return $value;
      // code to generate default flex field here
      return $value;
  • @JohnHuber

    Ok, thank you. By the way I am a developer and bought ACF a long time ago, at which then I felt it needed more to it. Since the last major update it is complete awesome, so I’ve dove into.

    In that context, I totally understand what you are saying, from an experienced developer point of view.

    It sounds like this would work. I will give it a try then.

    Do you think this could or should be a feature request? I thought it was a more natural expectation that requiring a minimum row layout would automatically load those those requires layout rows for the user to edit, as they are “required”. I didn’t think they would have to actually take an initial step to load what is required in the first place.

    I thought of making this a Feature Request in the spirit of UX. What do you think?

    .. And a again thank you for your detailed response! I appreciate it A LOT!

  • I’ve been using ACF for a long time, I wouldn’t build a WP site without it, but I do a lot of customization, like in the example above, to make it more usable for clients… or I should say, so that I don’t have to explain things to clients. The one thing that ACF has is enough filter hooks so that anything it does not do, it can be made to do. I guess that I’ve just been digging around in the ACF code for so long that adding filters comes as natural to me as using get_field()

    You can submit it as a feature request, but I wouldn’t do it here. Anyone’s best bet at getting the developers attention it to open a new support ticket, but like you say, I also see things from the code/developer side of the equation. I can see how this might make it more usable under some conditions, but I also see how much work it would be to add it.

    I’m pretty much the main person that looks at these boards and answers questions on a regular basis, though there are some other people that answer questions at times, and I thank them a lot for the help. However, this is a user support forum and you’re only going to get replies from other users. Eliot, the actual dev of ACF, doesn’t actually come here often if at all. If he looked at every topic in these forums there would never be any progress made with ACF.

    Not sure what it was about the last update that has you more interested.

  • @JohnHuebner

    Thanks for this! Works perfectly.

    I understand about the work needed, which was my thought as well.

    After testing this out, perhaps not as much works as anticipated?

    Without actually loading any defaults, meaning to simply trigger the layout to be visible upon page load, if value is NULL this is all that is needed.

    add_filter('acf/load_value/name=FLEXIBLE_FIELD_NAME_HERE', 'NAME_OF_YOUR_FUNCTION', 20, 3);
    function NAME_OF_YOUR_FUNCTION($value, $post_id, $field) {
    	if ($value == NULL) {
    		$value = 
    		[0 =>
    				'acf_fc_layout' => 'FLEXIBLE_LAYOUT_NAME_HERE',
    		return $value;

    Any ‘key’ => ‘value’ below ‘acf_fc_layout’ will be relative to the fields in that particular layout.

    Thank you deeply brother for your other information regarding the support flow and yourself 😉 I much appreciate it.

    I think for now then, because this was actually rather simple and lighter than expected, I will leave it not requested as a feature.

    And one the main reasons for me initially going back to check out ACF was the nav menu fields. But of course I’ve chosen to stay and migrate (which I have already done) because there is a lot more. ACF 5 is the version I mention. The JSON option also interests me. I understand JSON from tweaks, etc., but have not worked with it personally. But it is on my list and now I have something to go along in that learning.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Flexible Content – How to auto show minimum required layout fields.’ is closed to new replies.