Support

Account

Home Forums General Issues How to update_field for checkbox when value and label format is used

Solving

How to update_field for checkbox when value and label format is used

  • Hi,

    I would like to know how to update_field for checkbox when value and label display setting is set.

    Thanks a lot

  • A checkbox field stores an array of values. This is the same no matter what the turn value is set to.

    Example – your choices are

    
    1 : One
    2 : Two
    3 : Three
    

    update the field to hold 1 check you use the value

    
    update_field('field_selector', array(1), $post_id);
    
  • Thanks.

    I understand that but it doesn’t work.

    It work for all checkbox field who has just “value” but doesn’t with this who has both label and value in return.

    Here is my upload :
    update_field(‘tags_de_lentreprise’, array($edition_societe_tag), ‘user_’.$user_id);

    Where $edtion_societe_tag is the value of the checkbox check in frontend.

  • Does the field have a value in the DB before you attempt to update it? If a value does not exist then you must use the field key.

  • It’s the same if I do it when the field is empty and it’s the first time I update it and when it was already set.

  • Try using field keys in the selector rather than field names.

  • I tried it’s the same.
    I think I will do it in another way.

    Thanks for your help.

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

You must be logged in to reply to this topic.