Hello. Thank you for contacting the Toolset support.
I have a checkbox with multi select field and an image field also.
==> Do you mean that you have checkboxes field? and one image field? is those fields created using Types? If yes, Can you please share screenshot of your custom fields group and show me how those fields are configured?
Yes, both fields are added in custom post type using toolset plugin. Attached images are of a post created manually. However I want to create post via a code. Can you help me?
Well - both images and checkboxes fields are stored in postmeta table.
Images:
- Images fields are stored with full URL of the image.
Checkboxes:
- Checkboxes fields are stored in a special format which is called serialized array. To save checkboxes values you should try to use the following code:
Thanks for revert. Can you help a bit more. I have following 3 values to be stored e.g. value1, value 2, value 3. How would this fit in your sample code?
Well - you should try to run the code, once you run it by replacing your field name, it will checkmark all the checkboxes you have automatically with the values you assigned already to your Types checkboxes field.
If you want to checkmark specific checkboxes, you can check the specific option within the following loop and make sure to unset that key.
foreach ($fields[$types_field]['data']['options'] as $k=> $v){
$arr[$k] = array(0=>$v['set_value']);
}