如何为一个postmeta保存多个文件?

时间:2016-08-12 16:23:59

标签: wordpress

我正在尝试从类型库(多个文件)上传文件并将其保存在帖子元字段中,并且我正在使用pods插件来创建此自定义字段,但是当我尝试保存此字段的附件值时它只保存第一个请求任何帮助如何使用wordpress功能或代码或我需要使用大括号中的什么功能我正在尝试和搜索一整天但我找不到任何我的代码

  $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;
}

1 个答案:

答案 0 :(得分:1)

我发现了一种简单的方法

   $pod_id = save_tutor_pod($user_data);

foreach ($certificates_ids as $id) {
    $is_added = add_post_meta($pod_id, 'certificates', $id);
}