Articles of attachments

How do i upload an image and return the image id?

I need to import images from an url and return the image id is it possible to make a function like this? <?php $link = ‘http://img.mywordpresstips.com/images/NI113D034-D11@12.jpg’; $title = ‘the image title’; $alt = ‘the image alt’; $image_id = insert_image($link, $title, $alt); ?>

Upload External images into WordPress Media

I want to upload Images into wordpress media programatically.. I got amazon Product images using sampleItemLookup.php based on ASIN number.. Now I want to post these product title, content and image into wordpress Post.. I finished to post title and content.. But I dont Know how to post the Image into wordpress from amazon product […]

Uploaded images not showing properly using wordpress

I need to insert post programatically in wordpress.. I finished to insert title and content.. But image is not uploaded and attached.. Can you suggest me.. $post_id = wp_insert_post( array( ‘post_author’ => $user->ID, ‘post_title’ => $Title, ‘post_content’ =>$Content, ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘guid’ => $site_url . ‘/?p=’ . $post_id ) ); $Featured_image = […]

How get all media from a posts category by db?

I need to obtain all media data from wp_posts table that are embeded in a specific post category. In other words, I need all media data from elementes incrusted in a list of posts elements. But I don’t know even where start to search… Thanks.

“Could not write file” error in wp_upload_bits function

I’m trying to scrape images from the web and upload the binary files by using wp_upload_bits (https://codex.wordpress.org/Function_Reference/wp_upload_bits) This works fine for about 95% of the images, but some images can’t be uploaded. I’m getting the following error: Could not write file %s. The full code for this error in the function is: $ifp = @ […]

How to remove post slug from attachment url

I am trying to be able to access all attachment images using the same url structure without post/page slug. Lets say I have 3 images, each uploaded to different post. These are my attachment urls: www.example.com/post1/img1/ www.example.com/post2/img2/ www.example.com/post3/img3/ and I want my urls to look like this instead: www.example.com/img1/ www.example.com/img2/ www.example.com/img3/ I am considering to […]

uploaded an image by wp_insert_attachment but its thumbnail isn't coming up on Media Library

I’ve uploaded an image using wp_insert_attachment in order to upload the image to a custom field. The image is attached to the custom field successfully, the data on DB is correct, all seems working fine except its thumbnail image isn’t showing up on Media Library. It isn’t a major problem,but I’m having a hard time […]

How can I make an attachment page for pdf uploads?

I have an attachment page for post images, so that when I click on the thumbnail (on the front end) it takes the user to the attachment page for that image, how would I do the same for pdf files, so that when I click on the direct link to the pdf on the front […]

How to check if link is attachment page before send to editor

I’m using a function to filter image and video links with “media_send_to_editor” to apply Lightview parameters. This is the function: function give_linked_media($html, $id, $caption, $title, $align, $url, $size, $alt = ”) { // only if user is sending video or image if ( (wp_attachment_is( ‘video’, $id ) ) || ( wp_attachment_is_image( $id )) ) { […]

Replace all broken images with a image

My wp-content/uploads folder of the month January got deleted accidentally and I have no backup of the same. Hence, I have thousands of broken image links (featured images of the posts). I would like to replace all these image links of different posts of the month with a single image everywhere in the database. What […]