0

I have a WordPress site and I created the multisite network by following the below URL

https://codex.wordpress.org/Create_A_Network

And I am trying to upload files from frontend uploader form. The image is being uploaded to the correct path but the function wp_get_attachment_url($attachment_id) is returning me wrong URL like bellow where site id is being included twice in the URL.

http://network.v1.blog.com/wp-content/uploads/sites/2/sites/2/2019/01/15.jpg

It should be

http://network.v1.blog.com/wp-content/uploads/sites/2/2019/01/15.jpg

Can anyone help me with this?

Thanks in advance.

  • What’s your code for uploading the image? – Jacob Peattie Jan 2 '19 at 10:40
  • How you get the var `$attachment_id? – bueltge Jan 2 '19 at 11:44
  • @bueltge assume $attachment_id = 4; I didn't post the full code. – Suman Jan 3 '19 at 9:24
0

I have the same issue just now, when I attach images to post programmatically, they appear as attached but in media, they show as broken images with duplicated "sites" path. I haven't found solution yet, did you?. This is the code for inserting attachment, the images insert correct, GUID for attachment shows correct path too.

//$filename is absolute image path , correct one.
$attachment = array(
                    'guid'           => $filename , 
                    'post_mime_type' => $filetype['type'],
                    'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),

                    'post_content'   => '',
                    'post_status'    => 'inherit'
                );

                // Insert the attachment.
                $attach_id = wp_insert_attachment( $attachment, $filename, $post_id);

                // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
                require_once( ABSPATH . 'wp-admin/includes/image.php' );

                // Generate the metadata for the attachment, and update the database record.


                $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
                wp_update_attachment_metadata( $attach_id, $attach_data );
|improve this answer|||||

Your Answer

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

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