Home Forums General Issues Checking several checkboxes from "update_field"


Checking several checkboxes from "update_field"

  • Hi there.

    I have a field with checkboxes with 5 checkboxes filled in.

    I do have a form that creates a post in my custom post type that will update all the ACF field in that post from what is filled in the form.
    Right now everything works except for the checkboxes.
    I have 5 checkboxes that I need to fill in.
    Right now my code is this:

    if(isset($_POST['sToOrder'])) {
            if(in_array('external', $_POST['sToOrder'])) {
                update_field('field_630c9c8100089', 'External', $postID);
            if(in_array('graphical', $_POST['sToOrder'])) {
                update_field('field_630c9c8100089', 'Graphical', $postID);
            if(in_array('Web', $_POST['sToOrder'])) {
                update_field('field_630c9c8100089', 'Web', $postID);
            if(in_array('tracking', $_POST['sToOrder'])) {
                update_field('field_630c9c8100089', 'Tracking', $postID);
            if(in_array('SEO', $_POST['sToOrder'])) {
                update_field('field_630c9c8100089', 'SEO', $postID);

    From my var dumps, this code gets the values of all the checkboxes if they are checked.
    But the ACF field will ONLY check the last checkbox that is checked.
    If I have checked for “Graphical, Tracking and SEO” it will only check the SEO checkbox in my post.
    Any idea how I can make this update so that it checks the checkboxes in back-end that is checked in the form?

  • Another problem I see that I have is a true/false field.
    This is my true/false field in back-end:
    <input type="checkbox" id="acf-field_630c9cc60008a-field_630c9fcb225c0" name="acf[field_630c9cc60008a][field_630c9fcb225c0]" value="1" class="" autocomplete="off">

    What name should I use here when I see 2 acf field values in name.
    This does not seem to work:
    update_field('field_630c9cc60008a', 1, $postID);

    I have tried all the names in the field. I have tried with:
    update_field('field_630c9cc60008a', 1, $postID);
    update_field('field_630c9cc60008a', "1", $postID);
    update_field('field_630c9cc60008a', true, $postID);

    But nothing works. It will not change at all.

  • I fixed the checkboxes by pushing the values into an array and then using update_field by placing the array in the $value field.
    Anyone that has any idea how to solve the True/False fields?

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

You must be logged in to reply to this topic.