update_post_meta()不适用于可下载文件

时间:2016-09-04 17:13:01

标签: php wordpress woocommerce

我正在尝试运行查询更新woocommerce可下载产品。以下是我正在使用的代码:

if($_FILES){
    $attachment_id = media_handle_upload( 'abe_update_epub', $post_id );
        if ( is_wp_error( $attachment_id ) ) {
            $errors = $attachment_id->get_error_messages();
            foreach( $errors as $error ){
                echo $error;
            }
            echo 'There was an error uploading the image';
        } else {
            $file_name = 'Epub Files';
            $file_url = wp_get_attachment_url($attachment_id);
            $files[md5( $file_url )] = array(
                'name' => $file_name,
                'file' => $file_url
            );      
        update_post_meta( $post_id, '_downloadable_files', $files );
            echo 'The image was uploaded successfully!';
     }
}

我的文件已在媒体上成功上传,但未在产品中更新我的可下载文件。它在可下载的文件中显示为空白。

所以,请帮助我,告诉我我在代码中做错了什么,或者其他一些代码会有效吗?

0 个答案:

没有答案
相关问题