0

I built a front end form but suddenly cannot submit my image attachments.

Refer to these articles which do not get it done: http://voodoopress.com/including-images-as-attachments-or-featured-image-in-post-from-front-end-form/ http://goldenapplesdesign.com/2010/07/03/front-end-file-uploads-in-wordpress/

What is the best way for images to be added to the media library or only attached to the post and be manageable thereafter?

1 Answer 1

0

I found a working solution. This handles the uploaded files by attaching them to the post and display them in the loop. Still no featured image is set.

if ( $_FILES ) {
    foreach ( $_FILES as $file => $array ) {
        $newupload = insert_attachment( $file, $pid_buy );
    }
}

function insert_attachment( $file_handler, $post_id, $setthumb='false' ) {

    if ( $_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK ) {
        __return_false();
    }
    require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
    require_once( ABSPATH . "wp-admin" . '/includes/file.php' );
    require_once( ABSPATH . "wp-admin" . '/includes/media.php' );
    $attach_id = media_handle_upload( $file_handler, $post_id );
    return $attach_id;
}

function show_all_thumbs() { // displaying the attached thumbs
    global $post;
    $post = get_post( $post );
    /* image code */
    $images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=' . $post->ID );
    if ( $images ){
        foreach ( $images as $imageID => $imagePost ){
            unset( $the_b_img );
            $the_b_img  = wp_get_attachment_image( $imageID, 'thumbnail', false );
            $thumblist .= '<a href="'.get_attachment_link($imageID).'">'.$the_b_img.'</a>';
        }
    }
    return $thumblist;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.