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
0
votes
1answer
12 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
18 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
19 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
37 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
28 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
20 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
15 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
24 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
14 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
37 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
16 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
29 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
38 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
24 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
18 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
29 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
20 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
27 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
13 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
13 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
20 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
33 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
14 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
11 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 ...
0
votes
0answers
77 views

Make alt text required when setting a featured image

In the EU it will shortly be a requirement for public sector websites to have alt text for uploaded images. My organisation's users are rubbish at adding alt text, however, and I'm trying to find a ...
0
votes
2answers
77 views

How to restrict add media library only to images of the same post family?

So when I am creating a post, I would like to only be able to see images (after clicking ,add media above wp editor) that have been uploaded and attached to posts of the same family of the current ...
0
votes
0answers
9 views

How can you create a link to the first attachment (gallery item) of a wordpress post?

I am using ACF, and I am not sure if using that is the right approach to this. I am also using Elementor, and when creating the repeatable object I am using, I want to embed a 'link' or something to ...
0
votes
0answers
21 views

Media item permalink goes to source file instead of attachment.php

My Media Library permalinks are bringing up the source items directly and seem to be ignoring my attachment.php file. This is happening for both attached and unattached files. I'm trying to use ...
2
votes
1answer
25 views

How can I save the original filename to the database?

Currently Wordpress gets an attachment name from the exif title value for images: <?php // Use image exif/iptc data for title and caption defaults if possible. } elseif ( 0 === strpos( $type, '...
0
votes
0answers
26 views

How can I add a download button in a WordPress attachment page for the attachment

I am making a wallpaper site and clicking on an image will take you to the attachment page of that image. How can I put an automatic download button which will call the image link for that particular ...
0
votes
1answer
63 views

Get post attachment with post id

I have a form where user can upload a file, which creates a post with an attachment. I would like to get this attachment with post id, because this is the only thing I have in my case. Is it possible ?...
0
votes
0answers
14 views

Some Images are not showing on attachment page?

I have a problem with images. I can see my uploaded images, as previously, through the media library. I can access each image by clicking on "edit". But if I then click on "View Attachment Page", ...
1
vote
1answer
45 views

wp_set_object_terms not updating database without a die()

I have added custom taxonomy to media attachments. From the individual post page these are updating correctly, with some tweaks to get the column count updating correctly - and I can see these changes ...
0
votes
0answers
20 views

How to view exact image dimensions of a media in Admin view?

I know programmatically we can see the attachment sizes in templates, but I'm looking for a way to see the precise dimensions of the resized medium, large, xlarge sizes too. No plugin seems to do this,...
0
votes
0answers
62 views

Retrieving Gutenberg image block's caption

I have been trying to retrieve the image block's caption text to use in a PHP file. I understand Gutenberg (Block Editor) is relatively new so I haven't found any documentation on this topic. I have ...
0
votes
1answer
16 views

Get list of posts from attachment

My gallery has dozens of images. Next to each image, there should be links to the posts attached to that image. (You can see these in Media Library, under "Uploaded To"). I am able to retrieve the ...
0
votes
0answers
51 views

how to get custom attachment url?

Is there a common method to get a custom attachment URL regardless of the plugin or custom code used? Say if I use ACF plugin I can create an image field and get the url with get_field('fieldname'); ...
2
votes
0answers
31 views

How to change ID of an attachment in wp_posts and its related tables correctly?

I have two posts in my wp_posts table where post_type='attachment' The picture below shows the records related to those in wp_postmeta table I need to change the IDs of those files. What I am doing ...
0
votes
0answers
16 views

select Multiple file from Media on mobile device

on a front end form I am using media uploader to attach multiple images to a posts. however on mobile device I can not select multiple images from the media. is there a workaround?
0
votes
0answers
16 views

How can I add links to posts and pages using a particular image from its own media attachment page?

I have various media attachment pages e.g. https://www.artobatours.com/rock-art-abric-del-mas-den-ramon-den-besso-muntanyes-de-prades-catalonia/ where I have the image and some exif data. Along with ...
0
votes
1answer
33 views

Delete attached images from posts

I exported posts from site X to Y. But in every post on site X there was image attached to it (not featured image) <a href="http://x" rel="attachment wp-att-25425"><img src="x/wp-content/...
0
votes
0answers
45 views

Filter not applied to all image sizes

I have a callback applied to wp_get_attachment_image_attributes to add attributes to the generated image html. function add_lazyload_to_attachment_image($attr, $attachment) { if (strpos($attr['...
0
votes
0answers
45 views

Using unzip_file() to get contents of file

With each post, I save a zip folder as an attachment containing a json file with large amount of data. When looping through posts, I need to open this folder and retrieve the contents of json file but ...
0
votes
0answers
54 views

Zip a file and add as attachment

I first add support for mime type attachments // ADD MIME TYPEs FOR ATTACHMENTS add_filter( 'upload_mimes', 'my_myme_types', 1, 1 ); function my_myme_types( $mime_types ) { $mime_types['txt'] = '...
0
votes
1answer
34 views

Nothing found in uploads folder after wp_insert_attachment

I'm trying to add a text file as an attachment I first enabled the mime type add_filter( 'upload_mimes', 'my_myme_types', 1, 1 ); function my_myme_types( $mime_types ) { $mime_types['txt'] = 'text/...
0
votes
0answers
81 views

I want to view PDF files in attachment page (attachment.php)

I want to view PDF files in attachment page (attachment.php) When uploading a PDF file it is not reviewed but appears as a link to download
0
votes
0answers
184 views

Attachment metadata randomly missing

I have this website with about 3000 posts and 4000 images in the media library. For a long time now, some image thumbnails will randomly disappear from the media library: When I click to open the ...