0

I created an external upload script for bulk uploading post on per line basis of course the context of this will be hard to see without seeing it, so I attached an image.

enter image description here

Each line using my script is a new post created, and the title is populated via the $data['title'] portion displayed in our array below.

$my_post = array(
    'post_title'    => $data['title'],
    'post_status'   => 'draft',
    'post_author'   => 1,
    'post_category' => array(2),
    'post_date' => date('Y-m-d H:i:s')
);

$post_id = wp_insert_post( $my_post );

The functions are working beautifully, how ever it floods my entire media gallery with the image we upload using the form button above and submitted using the below code.

foreach ($matches as $match){   

$data['title'] = str_replace('.mp3', '', $match["song"]);
$modify = str_replace('/v/', '/downloadMusic?key=', $match["url"]); 
$direct = str_replace('/file.html', '', $modify);

        $my_post = array(
                'post_title'    => $data['title'],
                'post_status'   => 'draft',
                'post_author'   => 1,
                'post_category' => array(2),
                'post_date' => date('Y-m-d H:i:s')
        );

        $post_id = wp_insert_post( $my_post );


$upload = wp_upload_bits($_FILES["image"]["name"], null, 
file_get_contents($_FILES["image"]["tmp_name"]));

$filename = $upload['file'];
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => sanitize_file_name($filename),
    'post_content' => '',
    'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
set_post_thumbnail( $post_id, $attach_id );

wp_set_post_tags( $post_id, $post['genre'], true );
wp_set_post_terms( $post_id, $match["url"], 'ID' );
wp_set_post_terms( $post_id, $match["url"], 'SECONDID' );
wp_set_post_terms( $post_id, $drake, 'MIRRORID' );
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.