Support

Account

Home Forums ACF PRO Saving checkbox values to a new post using update_field()

Unread

Saving checkbox values to a new post using update_field()

  • Hi, I’m using the code on this page: https://www.advancedcustomfields.com/resources/update_field/ to import data from a database into my custom post type.

    The text options work fine, but I’m having trouble with the checkbox option.

    Your sample uses this as the value: $value = array(“red”, “blue”, “yellow”);

    In my database the data is stored as comma separated, so it doesn’t work if I use: $value = $row[‘features’];

    So I added a bit of php to add the quote marks:
    $mystring = $row[‘features’];
    $result_string = “‘” . str_replace(“,”, “‘,'”, $mystring) . “‘”;

    If I then use: $value = array($result_string); it doesn’t work and the checkboxes aren’t checked in WordPress. If I use the values like your example it’s fine. If I echo $result_string it displays as it should but doesn’t work as a variable.

    What am I doing wrong? This is driving me mad and there doesn’t seem to be any axamples.

    Also, how can I deal with importing image fields which are only stored as an image name in the database?

    Many thanks,
    Mike

Viewing 1 post (of 1 total)

The topic ‘Saving checkbox values to a new post using update_field()’ is closed to new replies.