Home › Forums › Add-ons › Flexible Content Field › Flexible Content – How to auto show minimum required layout fields. › Reply To: Flexible Content – How to auto show minimum required layout fields.
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 https://www.advancedcustomfields.com/resources/acf-load_value/ 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) {
var_dump($value);
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
var_dump($value);
return $value;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.