I finally figured this out. I needed to do
update_field( 'field_59f6d4dd91fcd', $post_id_of_post_I_want_to_connect_to, $post_id );
This gives me the post_title as the post_object. Is there a way to populate the field – field_59f6d4dd91fcd with a different field within that post?
To clarify – I have a post that has a acf field ‘team_code’. This is the value I want to set as the value for field field_59f6d4dd91fcd. I am now getting just the title of the post that includes the team_code. How do I get the actual text value of team_code?
The $test_code is the VALUE of the field I want to populate, not a post_id. Do I need to send an array as the $test_code which includes the value and a post_id?
I’m not sure what ‘post ID (Integer) that represents the post you want to set the field’ means – what post_id should be here? can you please clarify?
$post_id is the post_id of the post where I want to populate the value.
Yes, it is a post object field. Sorry if that wasn’t clear.
I need to take the value of the $team_code and put it into the post object field in my post.
rgar() is a gravity form function. It takes the value from the form field. This is the value I would like to obtain. eg $team_code = 101.
How do I populate an acf field in the database (and in the new post I am creating) with this value? The acf field is a post object.
What is the correct way to do this?
Thanks
This is the documentation I can find for update field
https://www.advancedcustomfields.com/resources/update_field/
is it different to the post object type?
How can I pass the $team_code value, which is the value I want to the field and the other necessary information ie the post object id?
Thanks
no, $team_code is the value of the field. $post_id is the post id.
Isn’t that the correct structure?
thanks I’m using the gravity form hook add_action( ‘gform_after_submission’, ‘update_hebrew_acf_fields’, 10, 2 );
works perfectly.
Issue solved
The gravity form creates a new custom post type and I can get the ID of this post and other posts written by the same author.
What hook should I put the update_field in?
I want the fields to be loaded when I first go in and edit the page, not after I save the post, since a lot of the fields are mandatory and I can’t save the post without filling them out. So add_action(‘acf/save_post’) doesn’t do what I need here.
What hook should I use?
issue fixed.
There was a spelling error in the field name.
The confusion was that the old posts were displaying the field correctly, maybe this is a caching issue?
Thank you, this was helpful and I can get the Hebrew showing now.
I did var_dump and it returned:
array(22) {
["ID"]=>
int(29)
["key"]=>
string(19) "field_56d2d662eda3d"
["label"]=>
string(11) "I work with"
["name"]=>
string(11) "i_work_with"
["prefix"]=>
string(0) ""
["type"]=>
string(8) "checkbox"
["value"]=>
array(2) {
[0]=>
string(7) "Couples"
[1]=>
string(3) "Men"
}
["menu_order"]=>
int(15)
["instructions"]=>
string(0) ""
["required"]=>
int(1)
["id"]=>
string(0) ""
["class"]=>
string(0) ""
["conditional_logic"]=>
int(0)
["parent"]=>
int(8)
["wrapper"]=>
array(3) {
["width"]=>
string(0) ""
["class"]=>
string(0) ""
["id"]=>
string(0) ""
}
["_name"]=>
string(11) "i_work_with"
["_input"]=>
string(0) ""
["_valid"]=>
int(1)
["choices"]=>
array(9) {
["Children"]=>
string(8) "Children"
["Adolescents"]=>
string(11) "Adolescents"
["Adults"]=>
string(6) "Adults"
["Couples"]=>
string(7) "Couples"
["Families"]=>
string(8) "Families"
["Men"]=>
string(3) "Men"
["Women"]=>
string(5) "Women"
["Geriatric"]=>
string(9) "Geriatric"
["Other"]=>
string(5) "Other"
}
["default_value"]=>
array(0) {
}
["layout"]=>
string(8) "vertical"
["toggle"]=>
int(0)
}
The translation is working for the ‘edit post’ but when I view the page it still only shows the English.
How do I make it show the Hebrew on the hebrew page?
I’ve set the choice in the field to:
Children : יְלָדִים
Adolescents : מתבגר
Adults : מבוגרים
Couples : זוגות
Families : משפחות
Men : גברים
Women : נשים
Geriatric : גֵרִיאַטרִי
Other : אחר
I’m using the_field(‘i_work_with’);
Do I need to use something different for a translation language?
The field_name is the same in both languages…
Your code works, but only for a text field, not for a repeater field.
I got it working for a repeater field using the code below:
`function my_acf_post_fields($post_id){
$post_id = get_the_id();
$post_author_id = get_post_field( ‘post_author’, $post_id );
if( have_rows(‘add_full_address’, ‘user_’ . get_post_field( ‘post_author’, $post_id )) ):
$i = 0;
while( have_rows(‘add_full_address’, ‘user_’ . get_post_field( ‘post_author’, $post_id )) ) : the_row();
$i++;
$value{$i} = get_sub_field(‘add_address_1’);
$value2{$i} = get_sub_field(‘add_address_2’);
$value3{$i} = get_sub_field(‘add_city’);
$value4{$i} = get_sub_field(‘add_zip_code’);
if( have_rows(‘c_address_of_your_clinics’) ) {
$i = 0;
while( have_rows(‘c_address_of_your_clinics’) ) {
the_row();
$i++; update_sub_field(‘c_address1’, $value{$i});
update_sub_field(‘c_address2’, $value2{$i});
update_sub_field(‘c_city’, $value3{$i});
update_sub_field(‘c_zipcode’, $value4{$i});
}
}
endwhile;
endif;
}
add_filter(‘acf/save_post’, ‘my_acf_post_fields’, 20);
However, it is not lopping through all the rows, it stops at the first row.
How do I make it look through and display all the row values.
Do I need to change the order of the if() and while() loops?
I tried:
function my_acf_post_fieldb($post){
$post_id = get_the_id();
$post_author_id = get_post_field( ‘post_author’, $post_id );
$field[‘readonly’] = 1;
$field_key = “field_573d8df4646da”;// field_key of repeater field
$value = array(
array(
“c_address1” => “Foo”,
“c_address2” => “Bar”
)
);
$field = update_field($field_key, $value);
return $field;
}
add_filter(‘acf/save_post hook’, ‘my_acf_post_fieldb’);
and it isn’t working either. The fields are not being populated with values.
What do I need to return out of the function? I tried return $post; it doesn’t work either.
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.