Support

Account

Home Forums General Issues updat_field not working for postobject\'value

Solving

updat_field not working for postobject\'value

  • i have post object tht needs to be set or updated based on the text i m using update_field for the same but it doesn’t update the selected value for the post object in the post

    <?php
    
    $allposts= get_posts(array('post_type' => 'genres', 'numberposts' => -1));
    $newgenre="MYSTERY";
    
    foreach ( $allposts as $post ) :  setup_postdata($post);
    if (!empty($post))
        {
        update_field('genrelist',$newgenre,$post->ID);  
        }
    
    endforeach;
    ?>
  • Hi @littledevil

    What field type is ‘genrelist’?

    If it is a post_object or relationship field, you can’t save “MYSTERY” as the value, you instead need to save a numeric value of the post’s ID.

    If the field type is a text based field, your code should work.

    If the field ‘genrelist’ is a new field and has not yet been saved on the fields, please read over the docs below to understand why you need to use the field_key instead of the field name
    http://www.advancedcustomfields.com/resources/update_field/

    Thanks
    E

  • awesome it works 🙂

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

The topic ‘updat_field not working for postobject\'value’ is closed to new replies.