Support

Account

Home Forums General Issues How to set checkbox custom fields through add_post_meta

Helping

How to set checkbox custom fields through add_post_meta

  • I have to import posts through CSV.

    I have Checkbox type custom fields, Which should have multiple values. I am using csv import plugin.

    Suppose, Custom field meta_key => ‘checkbox_key_name’ which has multiple ‘meta_value’

    I am doing below code

    $items = array_map('trim', explode(',', $v));
                        echo '<pre>';
                        print_r($items);
                        foreach ($items as $item) {
                            add_post_meta($post_id, $k, $item);
                        }

    But it is not setting 2 checked value for Checkbox custom field

  • Hi @denishvachhani

    ACF expects an array to be saved.

    Please use the update_field function and send through an array of values to be saved as the $value param

    Please also read the docs for this function before using it

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

The topic ‘How to set checkbox custom fields through add_post_meta’ is closed to new replies.