Reputation: 2370
i'm trying to upload and save files in a post meta field from type gallery (multiple files) and i'm using pods plugin to create this custom field but when i'm trying to save the attachment values for this field it save only the first one please any help on how to do this with wordpress function or code or what function in pods i need to use braces i was trying and searching all the day but i couldn't find any my code
$uploaded_files = upload_files();
$certificates_ids = array();
foreach ($uploaded_files['certificates'] as $certificate){
$certificates_ids [] = $certificate['attach_id'];
}
$user_data = ['first_name' => $user_first_name,
'last_name' => $user_last_name,
'skype_account' => $user_skype,
'email' => $user_email,
'phone_number'=> $user_mobile,
'age'=> $user_age,
'date_of_birth' => $user_birthday,
'gender' => $user_gender,
// 'video' => pods_attachment_import($video_data),
'video' => ($uploaded_files['videoupload']['attach_id']),
'nationality' => $user_country,
'bio' =>$user_bio,
'post_title' =>$user_first_name.' '.$user_last_name,
'tutor_available_time' => $tutor_days,
'tutor_image' => pods_attachment_import($image_data),
'certificates' => json_encode($certificates_ids)
];
$pod_id = save_tutor_pod($user_data);
//save tutor pod
function save_tutor_pod($tutor_data)
{
// save new pod record
$pod = pods('tutor');
$pod_id = $pod->save($tutor_data);
// return false in case of error
if (!$pod_id)
return false;
return $pod_id;
}
Upvotes: 0
Views: 84
Reputation: 2370
i found a simple way to do this
$pod_id = save_tutor_pod($user_data);
foreach ($certificates_ids as $id) {
$is_added = add_post_meta($pod_id, 'certificates', $id);
}
Upvotes: 1