Last active
August 29, 2015 14:27
-
-
Save jennschiffer/7542b6cea4999049c97f to your computer and use it in GitHub Desktop.
wordpress custom meta upload for post and/or taxonomy question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
thnx for the help, EAL | |
*/ | |
// acceptable file types | |
$supportedTypes = array('image/jpeg','image/gif','image/png','image/bmp','image/tiff'); | |
for ( $i = 1; $i < 4; $i++ ) { | |
if ( !empty($_FILES['bocoup-work-secondary-images-' . $i]['name']) ) { | |
$uploadCheck = wp_check_filetype(basename($_FILES['bocoup-work-secondary-images-' . $i]['name'])); | |
$uploadType = $uploadCheck['type']; | |
if(in_array($uploadType, $supportedTypes)) { | |
$mediaAttachment = media_handle_upload( ('bocoup-work-secondary-images-' . $i), $post_id ); | |
if(isset($mediaAttachment['error']) && $mediaAttachment['error'] != 0) { | |
wp_die('There was an error uploading your file ' . $mediaAttachment['error']); | |
} | |
else { | |
// upload as attachment | |
add_post_meta($post_id, 'bocoup-work-secondary-images-' . $i, $mediaAttachment); | |
update_post_meta($post_id, 'bocoup-work-secondary-images-' . $i, $mediaAttachment); | |
} | |
$upload = ''; | |
$uploadType = ''; | |
} | |
else { | |
wp_die("Error: The upload file type must be in JPEG, GIF, PNG, BMP or TIFF."); | |
} | |
} | |
} | |
?> |
media_handle_upload()
is in your future. wp_upload_bits()
upload files but won't create an attachment object, media_handle_upload()
will.
thaaaaaaaaaaaaaanks babe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this may be the ticket https://gist.github.com/hissy/7352933