Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
13 views

wp_get_attachment_image_src calling wrong location

We are using the Exopite Simple Options Framework framework in our plugin. One of the fields is an image upload metabox: This works fine and images are uploaded and attached to the post as expected....
0
votes
0answers
16 views

Remove product category placeholder image (Woocomerce)

I'm trying to get rid of placeholder product category images on the shop page. Right now I'm using this code to add a .no-image class to products that don't have an image so I can style them ...
0
votes
0answers
16 views

How to get attachments urls if text match?

Is there any plugin or code that can help me in this. I want to fetch images that have to include text in their file name that I mention on my page or in code. I mean I want to display all images if ...
0
votes
0answers
25 views

How to get attachment URLs one by one, not in loop [duplicate]

<?php global $post; $args = array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', '...
-1
votes
0answers
20 views

How to get attachments outside loop [duplicate]

I want to display my attachments to outside the loop or one by one. I know I can insert images into post one by one where i want to show them in post. but i want to achieve this via php code as i need ...
0
votes
1answer
6 views

Updating the attachment from front end doesn't show the new change

I am submitting an image to the db like this: if (isset($_POST['uploadImgCustom'])) { $myNewImg = get_post_meta($id, 'usp-file-single', true); } $attachments = get_posts(array( 'post_type' =&...
0
votes
1answer
18 views

Dupplication of Custom Post Type while adding attachment

I'm facing an annoying issue that I can't solve. I've made this code in order to add or update an attachment on a custom post type : function add_update_attachment( $postID, $photo ) { if ($...
0
votes
0answers
16 views

Attachment Size Gutenberg

I use the Gutenberg Editor in Wordpress and I will show the attachment size next to the download button on the frontend. Is this possible?
0
votes
0answers
14 views

Attachment page slug changed after editing permalinks

We run into a little problem, we are using the YOAST seo plugin that redirects the attachment page to the attachment it self. All cool. But after we change the permalinks from %postname% to %category%...
0
votes
1answer
21 views

wp_mail not sending attachment

My mail function is as follows add_action('wp_ajax_order_processing', 'order_processing'); function order_processing(){ include 'mail-translations.php'; require_once( ABSPATH . 'wp-admin/includes/...
1
vote
2answers
25 views

How to do string attachment with wp_mail

I'm using a gift card plugin for my woocommerce shop and I would like to add a generated pdf file to allow customers to download the gift card as a pdf. The idea is to use TCpdf or Fpdf to generate ...
0
votes
1answer
16 views

Using delete_attachment to prevent an attachment not working

I'm having an issue where the attachment is being deleted despite me returning false function action_maybe_delete( $id ) { echo "Let's not delete Attachment id: " . $id ; // prevent the ...
0
votes
1answer
8 views

Remove post with attachments hook

So I have a link that removes a post. I also have some code in my functions.php wich should be hooked to the wp_delete() function. However. The function doesn't seem to work. What am I doing wrong? ...
0
votes
1answer
45 views

copy attachments to another post type and change attachment url

On my site I have to custom post types and a function that let's users import photos from post type A to post type B, copying the meta values and it copy's the image to the folder specified for post ...
0
votes
0answers
33 views

wp_delete_attachment doesn't delete image files / doesn't work

wp_delete_attachment should delete everything that is about attachment. However if I do wp_delete_attachment( (int)$delete_attachment_id, true ); The files remain on the server (even true should ...
1
vote
0answers
17 views

Is it possible to share media files between multiple WordPress sites?

We've got around ten or so WP sites on different instances of WP (each with it's own database), most of them are on the same server but not all of them. We would like to achieve a situation where an ...
0
votes
0answers
11 views

automatically move to media library

I need to move the attached images by users when using the insert from url option, and move those images automatically to the media library. Anyone know of any plugin to do this?
0
votes
1answer
34 views

Get attachment URL from attachment Link in WordPress

I have been trying to fetch the URL of image attachments ( e.g. - http:// localhost/mytheme/post-format-gallery/100_5478.jpg ) using their attachment links ( e.g. - http:// localhost/mytheme/post-...
0
votes
0answers
14 views

custom saved media attachments delete from media library but not physically from folder

I'm doing some image processing using ffmpeg which saves a new media file and then i attach this file to a post using wp_insert_attachment followed by wp_generate_attachment_metadata and ...
0
votes
1answer
25 views

Removing images deleted from uploads folder, from Media Library

How can I remove images that have been deleted from the upload folder, from the Media Library?
0
votes
1answer
16 views

Setting an image as post header (not featured image)

I am not a WordPress expert and need your support. Is there a way to create a button just like Set featured image but that button will allow us to attach an image to a post (from gallery) as a meta ...
1
vote
1answer
56 views

Adding Featured Image to Post programatically

How do I add a Featured Image programatically, given the URL/filename of the image, and Post ID associated with it?
0
votes
0answers
29 views

How can I use an image from an external source without uploading it to the media library

I am looking for a way to tweak my xml parser code to insert a url from an external source into a new post, instead of first uploading it to the website's media library and than adding the attachment. ...
0
votes
0answers
6 views

Determine From Database or Export File Whether Full Image or Not

I have a Wordpress export file. How do I tell whether an attachment is the original or not? I need to import the original and skip any versions of the original such as thumbnails, etc.
0
votes
1answer
23 views

How does WordPress treats attachments metadata in post content?

I understand that an "Attachment" object can have its own metadata in Media Library. However, it can also have it's own metadata in a post scope. How does WordPress deals with attachment metadata? ...
1
vote
1answer
40 views

Link to the parent post in attachment page

I want to show a link on the attachment page which takes one back to it's parent post. Currently in my theme I do not have that option, the links I get on the attachment page are Previous/Next links. ...
0
votes
0answers
14 views

Switch which IPTC field WordPress defaults to for the image title on upload

While looking at the core code documentation, I see wp_read_image_metadata() ( https://codex.wordpress.org/Function_Reference/wp_read_image_metadata ) decides how to populate image "titles" via this ...
1
vote
0answers
19 views

I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?

I realise comparing this particular website with all the other WP sites I've built that all the others have the image url in the guid column of the wp_posts table, yet this problem site just has "guid"...
1
vote
0answers
45 views

How can I attach Facebook Open Graph data to an Attachment Page?

I have code in my page header which properly creates the Open Graph tags for pages, posts, etc. However, when I attempt to Share an attachment post from the Media Library (not the actual attachment ...
3
votes
1answer
29 views

Display Single Attachment Image file size, uploaded date, resolution, file-name etc in Sidebar

Sorry for any wrong details. I am totally new to WordPress development. I am running a photo site. On single attachment page, I want to show the details (i.e upload date, filename, size, resolution) ...
2
votes
1answer
79 views

Display one random image, but only if landscape

I want to pull one random image and use it as a background image —- but ONLY if it's a landscape image. I found this post: https://stackoverflow.com/questions/37537577/wordpress-query-by-attachment-...
0
votes
1answer
19 views

How to open an attachment based on the date picker

I am creating an E-Paper kind of functionality in WordPress where the user will have to select a date from the date picker and the corresponding attachment will open. I looked all around but didn't ...
0
votes
0answers
144 views

Send data url string as an attachment in wp_email

We have a data url string of png image file here and we can pass it via ajax to a php function via button click. Now is it possible to convert it back as image file and add as an attachment to ...
0
votes
1answer
35 views

ajax delete value from custom field array

I have on my page a multi file upload that saves post attachments within a custom field --- if (!empty($_FILES['vidPix']['tmp_name'][0])) { $i = 1; $files = $...
1
vote
1answer
91 views

Email Attachment from Form Submit

I am currently encountering a very strange problem. With the help of two existing wordpress functions (wp_handle_upload and wp_mail) and a form that uses some custom ajax functionality to process my ...
0
votes
1answer
54 views

Save attachment custom fields on front end

I have a front end post form that lets users upload multiple photos and on there I have 2 input fields to try and save custom meta data for each attachment - $vid_pix = get_post_meta($v_Id, 'vid_pix',...
0
votes
0answers
7 views

redirect attachment media pages to a new directory

I'd like to add all my attachment media pages to a new category I created called "none" /none/. Then Im going to block /none/ in my robots.txt because I hate attachment media pages. So I tried the ...
0
votes
0answers
12 views

Using 'post_parent' only works sometimes for attachments

I need to get all attachments with a specific post parent. To do this I used the following code: //this doesnt work $attachmentsids = get_posts(array("posts_per_page" => -1, "post_type" => "...
0
votes
0answers
15 views

Rename All Attached Image on Post

I have this code from a plugin that renames all featured image, how can i make this to rename all attached images on my post not only the Featured Image. Thanks!: public function wpRFP_rename_fimg($...
1
vote
0answers
155 views

Send multiple attachments with wp_mail in PHP

I'm trying to send multiple attachments with wp_mail() , after some issues of attachments names (it displayed something like phprTxfd.pdf instead of file_name.pdf), i succeeded to display the name of ...
0
votes
0answers
140 views

Using wp_insert_attachment() with TCPDF to save PDF files

I am trying to generate dynamic PDF files, and for that I am using TCPDF. At one point I like to save those PDF files as attachments in WordPress and for that I would like to use wp_insert_attachment()...
1
vote
1answer
12 views

Get all attachment by post excluding featured and content inside

I have a portfolio where for each item i have some images inside the content, a featured image and a custom filed called "portfolio images". I want to get all images by post excluding the fetured ...
3
votes
1answer
125 views

media_handle_upload for local files?

I am creating an image on the server and storing it in a tmp folder. I would like to run a php file that takes this image, stores it in the default media directory structure and attaches it to a post ...
0
votes
0answers
231 views

Fetch wordpress video attachment with post ID

So I have wasted 5 hours of my life to figure how to fetch wordpress custom post videos and been unsuccessful and here i am. Looking for expert advice. My Requirement: - Fetch all video attachments ...
0
votes
0answers
212 views

How to attach file with wp_mail(). [duplicate]

I have a custom form by which i try to send email with a file attachment but attachment not send. I don't know well how it works. When i pass $attachment variable, email not working . Email is working ...
0
votes
0answers
18 views

Customize wordpress media uploader and attachment fields

I am trying to customize the wordpress media uploader. Example: Instead of two tabs(Upload files, Media library) I want to have one tab where Upload files comes before media library. But I don't want ...
0
votes
2answers
85 views

How to disable post-thumbnail from generation?

In my theme there is a set of add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 470, 680 ); which is actually generating one more image besides the default small,medium,medium-large,...
0
votes
1answer
8 views

Is there a function for getting the post/page that an attachment is related to?

I am working on a custom attachment.php template file for a theme and I want to make it link back to the document that the attachment is included within. Naturally an attachment may be in multiple ...
0
votes
0answers
11 views

Display audio file in audio.php

This is gonna sound stupid, but I couldn't find the answer anywhere: I need to have an attachment page for audio files (audio.php), but I have no idea how to display the media player on this page. ...
0
votes
0answers
34 views

How to redirect image files to original attachment post in wordpress?

How can I redirect the image files, so example domain.com/wp-content/uploads/75/2018/05/image-2423.png to the original post, whats attachmented to this image, or the attachment page of this image? (...