Home › Forums › Add-ons › Repeater Field › How to add row to ACF repeater field in Term › Reply To: How to add row to ACF repeater field in Term
Thank you, I did end up using integers in my ultimate solution. However, I couldn’t get add_row to work, my ultimate solution was the following:
function assign_internal_writer_callback($request)
{
$parameters = $request->get_params();
$outline_task = $parameters['outline_task']; //ID for Task associated with Stage Two
$write_task = $parameters['write_task']; //ID for Task associated with Stage Five
$user = $parameters['user']; //User ID
$project_set = $parameters['project_set']; //Project Set ID
if ($outline_task != '' && $write_task != '' && $user != '' && $project_set != '') {
update_post_meta($outline_task, 'user', $user);
update_post_meta($write_task, 'user', $user);
$team_size = get_term_meta($project_set, 'project_set_campaign_team');
$new_team_size = strval(intval($team_size[0] + 1));
//Need to follow this convention for field keys in order for them to display in UI
$user_field_key = '_project_set_campaign_team_' . $team_size[0] . '_user';
$role_field_key = '_project_set_campaign_team_' . $team_size[0] . '_role';
$user_key = 'project_set_campaign_team_' . $team_size[0] . '_user';
$role_key = 'project_set_campaign_team_' . $team_size[0] . '_role';
update_term_meta($project_set, 'project_set_campaign_team', $new_team_size); //This meta field holds the number of rows in the repeater, needs to be updated +1 to display in UI
update_term_meta($project_set, $role_key, 268);
update_term_meta($project_set, $role_field_key, 'field_5faa2bce9fe7c');
update_term_meta($project_set, $user_key, intval($user));
update_term_meta($project_set, $user_field_key, 'field_5faa2c0b9fe7d');
return get_term_meta($project_set);
} else {
return 'Please supply the correct request parameters: Outline Task ID, Write Task ID, Project Set ID and User ID';
}
}
I’ve had several issues where I tried to use ACF methods like update_field and add_row to solve a problem, and they weren’t working. I was able to update with native WP methods like update_post_meta and update_term_meta. Is there any reason I’m unaware of not to do this?
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.