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
0answers
212 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
1answer
269 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
98 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. ...
1
vote
0answers
60 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
296 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
124 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
89 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
22 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
553 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
92 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
1k 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
192 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',...
1
vote
0answers
751 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 ...
1
vote
1answer
26 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 ...
4
votes
1answer
626 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 ...
1
vote
0answers
377 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
2answers
418 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
9 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
35 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
1answer
309 views

How to get $attachment->ID in custom functions

This is what I have now within an attachment theme template... //GET THE URL OF THE ATTACHMENT $parsed = parse_url( wp_get_attachment_url( $attachment->ID ) ); $url = dirname( $parsed [ 'path' ] ) ...
0
votes
1answer
41 views

Remove all video attachment, both files and post/postmeta from database?

I am trying to make a function which deletes all the video files + the attachment post and attachments postmeta from the database. This should run when the user role is switched to "basic". And if the ...
0
votes
0answers
195 views

Custom permalink for attachment

I am trying to rewrite my permalinks for attachments, which would open the attachment.php post. I found some code from this answer and have modified it to look like this: function ...
1
vote
0answers
129 views

“Scattered” gallery

I'm building a theme for a portfolio-type site. I'm looking for something like this: This site uses some kind of Foundation Grid CSS to size the thumbnails using different sizes. My question is, ...
0
votes
1answer
24 views

Unable to get all the Posts Attachments

I want to retrieve all the image attachments from a posts and render it in a gallery. Some how the number attachments which is being returned is only one even tough the posts contains multiple image ...
1
vote
0answers
32 views

Prevent Delete Attachment by URL or When Submit

This code is working, which prevent being deleted by specific title: add_action( 'delete_attachment', 'check_relations' ); function check_relations( $post_id ){ if(get_the_title( $post_id ...
1
vote
1answer
58 views

Get attachments from a post

I created a snippet to get all attachment from a post, included attachments from comments. <?php $post_attachments = get_posts( array ( 'post_type' => 'attachment', 'posts_per_page' =&...
0
votes
0answers
106 views

Overriding Generated Attachment Post URL

For a plugin I am developing I need image uploads from a Custom Post Type to go to ./wp-content/uploads/clients instead of ./wp-content/uploads/{YYYY}/{MM}. I managed to solve this with the following ...
1
vote
1answer
40 views

Stopping WordPress from Auto Generating Image Files for Sizes

I have a custom post type with an image upload meta field. Every time I upload it an image with it though, I am getting extra image files for each of the predefined sizes from the theme's functions....
0
votes
0answers
162 views

File was uploaded, but it is not shown on media section of the dashboard

I managed to add an upload field to the user registration form of the website I'm building. I, also, was able to handle the upload. However, despite the file was correctly copied to the uploads ...
1
vote
1answer
455 views

How can I store a file in the database in the same way WordPress and ACF do?

I'm taking input from a Caldera Forms form which includes a user upload. This is returned as an array containing the file name: ["company_logo"]=> array(1) { [0]=> string(73) "https://...
0
votes
1answer
38 views

Get Video Attachment to post

There is a plugin that let’s me upload a title, description and image with a form. If you send it, it creates and automatic post with the title, description and the image. The code for showing the ...
0
votes
0answers
43 views

Unexpected issue when using attachment_fields_to_edit filter

I am developing my plugin to add a custom attachment fields. I used attachment_fields_to_edit filter (https://codex.wordpress.org/Plugin_API/Filter_Reference/attachment_fields_to_edit) to resolve my ...
0
votes
2answers
2k views

Auto create file and send it via wp_mail()

I am getting dynamic content on page load and sending it via mail using wp_mail(). Right now all contents going in body section of email but I want it to store in .doc(MS word) file and then send that ...
2
votes
0answers
298 views

Issue to get wp_get_attachment_image with cmb2

I have a problem get the image with cmb2, I have tried in many ways without successm according to the documentation, this is fine, what can I be doing wrong? add_action( 'cmb2_admin_init', '...
0
votes
1answer
927 views

Automatically delete attachments and posts [closed]

Does anyone know of a plugin or function that automatically deletes after a certain period posts and media from Wordpress? I have a news site and have news of more than 2 years that I want to delete ...
4
votes
3answers
475 views

How to get all files inserted (but not attached) to a post

How do I retrieve the IDs of unattached media in my post? I have two posts: POST A and POST B and a PDF file called file.pdf. I've uploaded file.pdf to POST A but then also inserted it in POST B. ...
0
votes
0answers
190 views

PHPMailer - Uploading a file

I'm using PHPMailer to send applications for jobs and can send over all the data except for the file e.g. word doc, PDF's. The process is; <input type="file" name="uploaded_file" class="...
1
vote
2answers
476 views

How can i change an image's author?

Is there any function to change the image Author(Uploaded By) in WordPress library?
0
votes
1answer
885 views

How to get all images in Media Gallery with pagination?

I want to get all images in the image gallery with pagination so that I can use infinite-scroll with it. The infinite scroll works but it's taking the posts' number of post, not the images. That ...
0
votes
0answers
51 views

Set attachment category from file name on upload

I use Media Library Assistant plugin and I extensively take advantage of its taxonomy, in particular the possibility of creating categories that can be assigned to images (categories that you define ...
0
votes
1answer
148 views

Add post meta programmatically to attachment

I have a function to create a meta key for my custom post types. It works pretty well for them but now I want to use the same function for the attachment post type. Normally it should work with the ...
0
votes
1answer
243 views

How to make the Broadcast plugin distribute images to several sites?

How to make the Broadcast plugin distribute images to several sites? I have the plugin from here: https://broadcast.plainviewplugins.com/basic/ And the problem lies in that does not distribute the ...
0
votes
1answer
109 views

How to use previous/next image link, ignoring parent posts/attachments?

I have a gallery page, made with the gallery shortcode. Each thumbnail image links to its image's attachment page, which uses the image.php template in my child of the TwentySixteen theme. If an ...
0
votes
1answer
82 views

Why having more than 10 clauses in WP_Query results in some outputs being dropped?

I don't want to have image IDs in the source code of the posts, so I fetch them using the_content filter - the auxiliary function that does the query is as below. It works fine when I get up to 10 or ...
1
vote
1answer
283 views

Detach an image from a page using php

I want to detach/unattach an image from the page it's currently attached to -- by using PHP, instead of the "Detach" link in the Media Library. I found this (in /wp-admin/includes/media.php#3164): $...
0
votes
1answer
113 views

Image Attachments Query Not Working If Post Is Loaded Via Ajax

Here's my problem: I'm trying to display a gallery of images attached to a post via ajax. The post is also loaded dynamically via ajax from the homepage. The query to retrieve the images however ...
0
votes
1answer
157 views

How to stop wordpress from injecting hard-coded style into image attachments with captions

Every time I add a caption to a wordpress image, wordpress decides its going to insert a hard coded style="" into the attachment html which breaks my sidebar. All images without captions are inserted,...
0
votes
1answer
50 views

Attachment page tag queries & posts not found

My objective is to alter the main query using pre_get_posts so I can search only through attachments and only ones that have specific tags assigned to them. These tags are displayed to the user using ...
0
votes
2answers
147 views

Run a function when new image is uploaded in media library

I want to run a function of my plugin that I am developing when ever user upload a new image to the library. How can I do that? Thanks in advance
0
votes
2answers
5k views

How do you get the full size url of an attachment image

I do not see a way to get the URL to the full sized image of an attachment. Yes, i can use get_the_post_thumbnail_url($post->ID, 'full'), but that is of no help if the image is not the featured ...

1 2
3
4 5
19