Forum Replies Created

  • 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?

  • This is the documentation I can find for 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?

  • 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) {
      string(19) "field_56d2d662eda3d"
      string(11) "I work with"
      string(11) "i_work_with"
      string(0) ""
      string(8) "checkbox"
      array(2) {
        string(7) "Couples"
        string(3) "Men"
      string(0) ""
      string(0) ""
      string(0) ""
      array(3) {
        string(0) ""
        string(0) ""
        string(0) ""
      string(11) "i_work_with"
      string(0) ""
      array(9) {
        string(8) "Children"
        string(11) "Adolescents"
        string(6) "Adults"
        string(7) "Couples"
        string(8) "Families"
        string(3) "Men"
        string(5) "Women"
        string(9) "Geriatric"
        string(5) "Other"
      array(0) {
      string(8) "vertical"

    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();
    $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’) ) {
    $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});
    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(
    “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.

Viewing 14 posts - 1 through 14 (of 14 total)