Home › Forums › Add-ons › Repeater Field › dynamically generate subfield content › Reply To: dynamically generate subfield content
Just in case anyone else needs this information.
So, to create an arbitrary number of subfields for a new post, if I have a repeater named “bf_test_repeater”
add_filter('acf/load_value/name=bf_test_repeater', 'afc_load_bf_test_repeater_value', 10, 3);
function afc_load_bf_test_repeater_value($value, $post_id, $field) {
if ($value === false) {
// this is a new post since value === false
// set value to number of default # of rows to create
$value = 5;
}
return $value;
}
I’ll have more code than this since it will need to figure out by looking at the options page how many rows to start with. Then I’ll need the code for each of the sub-fields to set the value to the next value retrieved from the options page.
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.