I hope someone can help point out probably the glaringly obvious!
I have some code which I know works to add a row into a repeater field on a user (user meta):
$row = array( 'field_595ceca2bddf1' => $job_id, 'field_595cecbabddf2' => $job_title ); $i = add_row('field_595cec87bddf0', $row, $user_id);
This works great when used with the acf/save_post function.
I therefore created an ajax script which is to do the same sort of thing.
When I test the ajax script with a single text field added to a user, it works perfectly fine when using the following in the ajax callback function:
update_user_meta( $user_id, 'test_field', $job_title ); # Update our user meta
So I know the callback works, it’s grabbing the values etc.
However, if I swap this over to:
# Insert data into the repeater $row = array( 'field_595ceca2bddf1' => $job_id, 'field_595cecbabddf2' => $job_title ); $i = add_row('field_595cec87bddf0', $row, $user_id);
It simply doesn’t add the row to the user repeater field.
Unless I’m missing something, I honestly can’t see why?
Any help is much appreciated!
Thanks in advanced.
Thanks John Huebner
I’ll take a look although it’s odd as the add_row code works inside the save_post function so not sure why it won’t in the ajax call
The ajax call may be creating the new row, but that will not add it to the admin unless you reload the page. ACF does not automatically refresh the content of the page after the ajax call.
But if it works for a single field why not a repeater (excuse my ignorance)
Even if I check the DB, not info is added, not even a new empty row
$i = add_row('field_595cec87bddf0', $row, $user_id);
$i = add_row('field_595cec87bddf0', $row, 'user_'.$user_id);
Note the user_ before the ID, otherwise it posts to the postmeta table not the usermeta table!
You must be logged in to reply to this topic.
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!
© 2020 Advanced Custom Fields. Subscribe