Questions tagged [attachments]

An attachment is an image or other file uploaded through the post editor's upload utility. Attachments can be displayed on their own 'page' or template. For more information, see Using Image and File Attachments.

Filter by
Sorted by
Tagged with
1
vote
0answers
24 views

wp_get_attachment_image_src() returns wrong url

wp_get_attachment_image_src() is returning a wrong image url. It returns the original url instead of the cropped one. Here some example code: $ptId = get_post_thumbnail_id( $productId ); ...
0
votes
1answer
6 views

wp_insert_attachment() dupplicate attachment posts

I made a function to add an image in WP and attach it to the right post. The specificity is the input is an url to get the picture. My problem is when wp_insert_attachment() is run I got a dupplicate ...
0
votes
2answers
21 views

How to echo images Urls from a wordpress post, that are relally in the post

I have a question. I use the following code to output the image URLs of a wordpress post. The image URLs are related to the "attached images" of a wordpress post and not the ones that are ...
0
votes
0answers
29 views

Front-end upload image, no image preview in media

I have form to upload image via Ajax, it's works efficiently. But image not have preview thumbnail like : if(isset($_FILES['file'])) { require_once( ABSPATH . 'wp-admin/includes/image.php' ); ...
0
votes
1answer
87 views

Frontend AJAX Media Upload returning 404

I am building a custom registration form for users where they have to upload an image of government ID. Using AJAX for submission. The handler function always returning a 404 status error, no matter ...
0
votes
0answers
12 views

Error 503 with wp_delete_attachment

I´m doing a plugin which must do an import from an api. Inside this import, I have to removed phisicaly pictures before saving new ones. For some reasons this line code wp_delete_attachment( $...
0
votes
0answers
16 views

How to upload an auto-generated URL Screenshot in a User Submitted Post?

I have a form that allows users to submit a post, and one of the fields is a URL. I would like the form to submit that post, and also upload a screenshot of the URL that is generated by the code. I ...
1
vote
0answers
11 views

Set size for attachments

I am working on a custom theme and have generated content with FakerPress to include some uploaded post images. I want to ensure any image uploaded as an attachment in a post displays in one of the ...
0
votes
1answer
34 views

How do I add html content to custom post type Posts using php?

I'm trying to do something that I'm sure is very basic, but I can not figure out how to do it. Here's the setup: I used the CPT UI plugin to create a custom post type called board_docs, and I used the ...
0
votes
0answers
22 views

How to enable Attachment post type in Gutenberg editor for blocks?

I would like to make the native Attachment posts to be accessible by various Gutenberg Blocks. (To appear & be selectable in dropdown menus, etc.) Is that possible? The nearest answer i found is ...
0
votes
0answers
12 views

Can't identify why code can't get attached images thumbnails urls

In my functions.php i'm trying to get the 'small' (thumbnail) urls of all the images attached to a post: $post_id = get_the_ID(); $images = get_post_meta( $post_id, 'user_images_upload' ); ...
0
votes
1answer
28 views

SQL: How to find all attachments that are not used in any posts/pages/custom_post_types

I have a wordpress installation where the posts also contain attachments that were not embedded in the content by using the media library -> add. I would like to find all attachments that are not ...
0
votes
1answer
27 views

How is it possible that a gallery doesn't have attachment ids?

I have a function that looks at the attachment IDs from a normal gallery (let's ignore Gutenberg galleries for now, they have a different structure altogether): \get_post_gallery( 0, False );, this ...
0
votes
1answer
22 views

Change attached img anchor link to post link

When I attached images, it nested in this hierarchy of html tags : <div id="attachment_ID" class="alignnone"> <a class="image-ID" href="https://image-link.jpg"> <img class="...
1
vote
0answers
31 views

How to get images from EDD post?

I use Easy Digital Downloads plugin and I wish to get images from the downloads posts types! But with my code, nothing return! Someone for help? <?php $attachments = get_posts( array( 'post_type' ...
1
vote
1answer
14 views

Get PDF in media by ID

On my search page, I've added all the file from the media with this code : function attachment_search( $query ) { $args = array( 'public' => true, '_builtin' => ...
0
votes
1answer
26 views

Attachment URL for an image is loading direct image file

I'm working on a site that is using a theme with an attachment.php file in the theme. However, when going to an image's attachment page (i.e. https://domain/john-doe/) it loads the direct image (i.e. ...
0
votes
1answer
15 views

Append Media/Attachment IDs to Gallery Shortcode HTML Output

I've been trying to find a simple and elegant solution to append the media/attachment IDs to my [gallery] shortcode html output. I've seen various functions to rewrite the whole output of the [gallery]...
0
votes
0answers
24 views

attachment_fields_to_save first parameter is null

I have the following code in a self-written plugin. In the function saveHomepageGalleryCheckbox the first param ($post) is always null. Did I something wrong? The second parameter ($attachment) has ...
0
votes
0answers
17 views

Media attachment page - custom URI, and trying to display differing links, based on that URI

I'm trying to edit the "media attachment" template. I have four image galleries, each one with a different URI. I want the media template to reflect the gallery in a link in the page. The media ...
1
vote
1answer
74 views

How can I get full attachment url from wp_get_attachment_metadata?

I want to get all sizes of an attachment. I can use wp_get_attachment_metadata to do this. But it only return filenames, not file urls. How can I do this? This is a workaround, but doesn't take ...
0
votes
1answer
27 views

Attach and retrive multiple pdf files to post or page

I need to create two sections that will respectively contains only some pdf to downloads. I've never used pdf inside a wordpress websites, my question is how I can display them or in any case had a ...
0
votes
1answer
17 views

how to redirect 404 to attachment.php?

I have a problem, I have many url attachments with / amp, example: siteweb.com/article-2019/image2/amp siteweb.com/article-2019/image3/amp siteweb.com/article-2019/image4/amp all these give me 404 ...
1
vote
1answer
75 views

Can't check if a post has thumbnail adding filter to get_post_metadata()

I need to set fake thumbnails to all posts which have yet no a thumbnail. I use the code from the link core.trac.wordpress.org/ticket/40547#comment:1 But I can't check if a post already has a ...
1
vote
1answer
61 views

Post edit - Media Library - Only get images from current post

I've got a few ACF Image fields for posts And I want to only query the images in the media library browser already uploaded and used on the current post. In other words, when opening the media library ...
0
votes
0answers
24 views

wp_insert_attachment adding numeral to file name

I have a situation where I am pulling images from an exterior wordpress blog, which also happens to have images. I am able to pull the links and titles of the latest posts, as well as the featured ...
0
votes
0answers
43 views

Unable to delete attached file from folder programmatically

I am unable to delete attached files from their folders programmatically or even through the wordpress admin as the admin user. The attachment record deletes from the database but the file remains in ...
0
votes
1answer
68 views

Were attachment media settings removed from Wordpress?

In the past, when selecting a picture in the media library, you could see the "attachment display settings". I installed wordpress 5.3.2, I uploaded an image to the media library. I don't see ...
0
votes
0answers
26 views

How to convert attachment pages to Posts?

I have mp3 files as attachments, I would like to have each attachment page considered as posts, Is it even possible?. Are there plugins that does it?. Importantly, I need to use the id3v2 tags of the ...
0
votes
0answers
27 views

Set external URL as attachment source

I'm interested if it's possible to use the WP media library with external images as sources. Basically, I need the ability to add the images to the post (via meta field that stores the connected ...
0
votes
1answer
28 views

Issue on Getting URL of Uploaded Image to a Custom Post Type

I have a CPT called books and I am able to loop through it like this but I need to get the URL of the uploaded images into the post (not in Gallery). I tried to use WP wp_get_attachment_image_src() as ...
1
vote
1answer
18 views

How to delete a custom file from upload directory when deleting its post

I'm storing an uploaded attachment to a custom directory under wp-content/uploads/my-directory/ and storing its value in wp_postmeta table. When I'm deleting the post it's not deleting the attached ...
1
vote
2answers
46 views

Easy way to delete 70k posts and attached media?

A plugin created lots of posts that I now need to delete. They are targetable by category (e.g. Tweet). Many also have attached images. I wrote a php script for it*, but without pagination it gets ...
0
votes
0answers
22 views

wordpress attachment image blurry on mobile

I am using below code to get the wordpress attachment image wp_get_attachment_image_src($img,'full') I am getting the image in the full resolution I am using it to display the images on a owl ...
0
votes
2answers
32 views

replace featured image from frontend

I'm using this code to add the alt text to my featured images on upload. $image_title = get_post( $post->ID )->post_title; // Sanitize the title: remove hyphens, underscores & extra spaces:...
0
votes
1answer
124 views

Media Library Mess After FTP … /uploads

I've got a Media Library mess on my hands. Transferred old site to staging server for redesign and uploaded large .../content/uploads via FTP after I was unsuccessful in importing media files thru the ...
0
votes
0answers
26 views

Hide WP Media Uploader Window

It might need some code written into functions.php if you have any idea about it. General task is to hide this modal WP uploader window And Use Simple Browser uploader instead of WP uploader Thank ...
0
votes
0answers
20 views

How can I get the Description textarea field to use the Visual Editor for Attachment Posts

I saw this post involving tags. But I can't figure out which /** * Display advanced TinyMCE editor in taxonomy page */ function wpse_7156_enqueue_category() { global $pagenow, $current_screen; if( ...
0
votes
0answers
40 views

Hide all files from specific subfolder in Media Library

I use a subfolder /pdf/ in the Uploads directory, in which specific PDFs are added via another plugin: Example: /wp-content/uploads/pdf/filename.pdf Is there any simple way to hide all these files ...
0
votes
0answers
49 views

Replace wp_get_attachment_image with lqip image size

I created the image sizes as follows, add_image_size( 'size-260', 260, 0, false ); //260px Original add_image_size( 'size-260-landscape', 260, (int) round( 260 * 0.7 ), true ); //260px Landscape ...
0
votes
0answers
37 views

Programmatically Upload Image to Media & CDN

I'm trying to create a feature that allows my website to: Crawl through a CSV file and programmatically create a post Upload a featured image based off a URL from the CSV file to the Media Library (...
0
votes
0answers
14 views

Add “Embed” Media type to Media Library

I'm looking for an alternative to the standard embedding work flow. I need all my embedded attachments to have the same meta data fields as uploaded content (description, caption, title, etc). The ...
0
votes
0answers
17 views

Function that automatically attaches the file size of any locally hosted file link/url

So we've got a site project with a site with lots and lots of existing pages that have standard file attachments links in the content editor and in ACF WYSIWYG fields. Simple locally uploaded ...
1
vote
0answers
14 views

how to get link of added document with a post

I am working on a mobile application with back-end wordpress database. In wordpress there is a button on each post container top with name of "Add Media" where we can add video , audio and documents ...
0
votes
1answer
22 views

Allow users to upload attachments to certain posts

I am hoping to get some possible solutions from you all :) I have 330 regions set up as a taxonomy category. Each region has it's own landing page displaying posts relating to that area. I wanted a ...
1
vote
0answers
10 views

How to show optimized list of posts with all their attachment images

In page-images.php template I have created this code which displays a list of posts which belong to a category and order them by meta value. So basically it is like a category page, generally nothing ...
0
votes
0answers
55 views

wp_delete_attachment returning successfully, deleting all DB data, but NOT deleting files

I digged into wp_delete_attachment here https://core.trac.wordpress.org/browser/tags/5.2.1/src/wp-includes/post.php#L5450 , it calls wp_delete_attachment_files wp_delete_attachment_files returns ...
0
votes
1answer
17 views

How to identify and delete all the images/pdf's which are not assigned to any post/custom-post/page and also which are repeated

I have more than 1000 custom posts. I run a cron job to pull the posts from the third party service. When I run the job every attachment is created by deleting the old one. But there are many ...
0
votes
0answers
16 views

Mass copy Alt text into Image Caption field for attachments

I have a site with lot's of images, which have only the Alt text field filled out. But some also have a Caption and other fields filled out. I need to set up a SQL query, which would first check, if ...
0
votes
0answers
12 views

Trying to get attached image to a post

I am trying to get the first attached media to a post but something is wrong. I use this <?php $media = get_attached_media( 'image' ); ?> <?php echo $media[0] -> guid ?> I got this ...

1
2 3 4 5
19