Home › Forums › Add-ons › Repeater Field › update_sub_field not working › Reply To: update_sub_field not working
Not sure if this help someone:
In my case “update_sub_field()” fails to update POST_META table:
It creates an additional record for the post without repeater name:
_0_subfield
_1_subfield
_2_subfield
and does’nt update the good records:
repeaterName_0_subfield
repeaterName_1_subfield
repeaterName_2_subfield
And from them it updates the wrong ones, “update_sub_field()” seems like the function fails to “add” repeater name to the meta_key, anyway I found a workaround:
Use the core function “update_post_meta()” :
update_post_meta( $post_id, “repeaterName_0_subfield”, “new value” );
update_post_meta( $post_id, “repeaterName_1_subfield”, “new value” );
update_post_meta( $post_id, “repeaterName_2_subfield”, “new value” );
This function update values in custom fields in Post_Meta table.
PD: If you need to know how many “rows” has your repeater you can use this:
$number_rows = get_post_meta( $post_id, “repeaterName” );
This works for me perfectly, I spend a lot of time struggling with update_sub_fiel(), hope there will be an update it soon.
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.