2022 Developer Survey is open! Take survey.

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
1 answer
32 views

How to get comment images stored as serialized comment meta

I want to display images under for each comment but images store in database as serialized a:3:{i:0;i:775;i:1;i:776;i:2;i:777;} I wrote this code print_r (get_comment_meta( $comment->comment_ID , '...
user avatar
0 votes
0 answers
20 views

How to get a list of all attachements urls for every post of a wordpress installation?

I'd like to retrieve a list of all attachment URLs for all posts of a website. This would bring something like http://example.com/mypost/attachment-1/ http://example.com/mypost/attachment-2/ http://...
user avatar
0 votes
1 answer
18 views

Set term on an attachment using wp_set_object_terms and want to display the full term text but it's showing a slug instead

I have a form that visitors use to upload files and fill out information about them and a function that adds those files to the media library and set various fields (including some custom taxonomies) ...
user avatar
  • 146
0 votes
1 answer
67 views

How to get an attachment id from a filename

I have not been able to find a reliable solution for how to lookup the id for attachments in the media library from a filename as Wordpress does not appear to provide such a function. Most solutions ...
user avatar
  • 79
0 votes
1 answer
49 views

Update media library image shown in "attachment details" when using wp_insert_attachment to add item to the media library

I'm using the function wp_insert_attachment() to run on a form submission from GravityForms, take a file uploaded in the form, and add it to the WordPress Media Library. Code in functions.php below, ...
user avatar
  • 146
1 vote
1 answer
24 views

Disable featured image

From the description of the plugin "Hide Featured Image": There are instances when one wants to show featured image on single post and hide it on another post. This plugin will allow you to ...
user avatar
  • 113
0 votes
0 answers
9 views

List all files from subpages

My goal is to list all the pages names as well as the "attached files" of these pages on a separate overview page in wordpress. I have 100 pages with each between 0 and 4 attached PDF files (...
user avatar
0 votes
0 answers
27 views

Add videos/images preview to bbPress attachment

In my blog I installed bbPress with few plugin such as GD bbPress Attachments, GD bbPress Tools and Image Upload for BBPress. When I create a new post, I can upload new images or videos and I can see ...
user avatar
0 votes
0 answers
17 views

get all images from the wordpress media library with link to the post they are associated with

I'm trying to get all the images from the wordpress media library with link to the post they are associated with. I'm using this code, I get all the images, but the link is the link to the URL of the ...
user avatar
0 votes
0 answers
36 views

Problem with inserting multiple images in gallery of each WooCommerce product programmatically

I am creating a script to programmatically add multiple images to the gallery of each WooCommerce product. The script works but only takes the first image, I'm having a hard time figuring out how to ...
user avatar
  • 1
1 vote
0 answers
84 views

Insert woocommerce products programmatically with featured image and gallery

I'm inserting WooCommerce products programmatically to the database, but I'm having trouble inserting and linking first image as featured image and multiple images for gallery assigned respectively to ...
user avatar
  • 11
0 votes
1 answer
18 views

wp_mail Allow Remote Attachments from CDN

I came across a problem with WP_Mail for sending form submissions with file attachments. Our site uses a CDN, so everything uploaded to the site, whether images and media by site builders or documents ...
user avatar
0 votes
1 answer
26 views

Does wp_get_attachment_image_src also work with non-image files?

I wish to get the file path to files other than images like PDF or TXT that are uploaded. Should I use wp_get_attachment_image_src or there's other function more suited for non-image attachments.
user avatar
0 votes
1 answer
25 views

Hook after attachment added and cropped

I am looking for hook, that fires right after image uploaded, cropped for thumbnails and data posted to database. I need it for image optimization after uploading. I tried add_attachment and it fires ...
user avatar
  • 21
0 votes
0 answers
28 views

PDF Upload from Input Error

I have a custom plugin that creates an input field under each post, that allows users to upload PDF files. $html .= '<input accept="application/pdf" type="file" id="...
user avatar
0 votes
0 answers
12 views

Search in posts' attachments: title, caption, description

I have seen variations on this question here and some have pointed to this solution (which doesn't work and is apparently syntactically incorrect as well). I have also seen people ask about searching ...
user avatar
  • 133
0 votes
0 answers
12 views

Auto embeds don't work for attachment descriptions

I am able to paste a Youtube link into a post and have it auto embed just fine, but if I go to edit a media description, and put the link there, and then view the attachment page for that media, it ...
user avatar
  • 133
0 votes
0 answers
20 views

Different image using srcset function

In a template I'm pulling in an image from the media library with: <?php echo wp_get_attachment_image( 33894, 'full', "", array( "class" => "lazyload" ) ); ?> ...
user avatar
  • 111
0 votes
1 answer
22 views

Returning data instead of echoing/printing

New to WordPress (and PHP) and am trying to get this PHP snippet to work with the Code Snippets plugin so I can display all media attachments within my post. It is working, in that it shows the ...
user avatar
  • 1
1 vote
1 answer
120 views

Display "large" image size and show caption in attachment page

On the attachment page for an image, I'd like to display the image in its "large" size. The current behavior is showing the "medium" size image. I'm using a theme I created from ...
user avatar
  • 146
0 votes
1 answer
76 views

Do custom post type (CPT) attachments/media store the parent post ID?

Do custom post type attachments store the parent post ID, and if so, how do I retrieve it. I need to prepend the ID of a CPT post to the uploaded media name, eg 123-my-file-name.pdf I do have this ...
user avatar
0 votes
0 answers
25 views

How to change an image source when rendering on frontend?

when showing articles, let's say there are images with watermark. But of course, those images are somewhere else, the watermark itself is not rendered onto the source image. So, just before rendering, ...
user avatar
0 votes
1 answer
41 views

submit two file input fields in the same form

I have a form which has two file input fields, each input should be submitted in different metabox in custom post type, when I try to submit the form it takes only the first one and ignore the second ...
user avatar
0 votes
0 answers
16 views

Keep all media unattached

I am using a template to display my attachments, with their metadata, and the site I'm building requires a lot of standalone media. Whenever someone sets a page thumbnail, or connects a post object to ...
user avatar
  • 133
0 votes
0 answers
32 views

How to modify an image Gallery block in WordPress?

simply i want to remove <figcaption> from every image and remove text between <figcaption> tag' <figcaption class="blocks-gallery-item__caption">Image caption</...
user avatar
  • 5
0 votes
0 answers
18 views

Processing resized images upon upload

WordPress creates resized copies of images that are uploaded to the media library. When I upload an image, I want to do some processing on these resized images. Currently, I'm using a add_attachment ...
user avatar
0 votes
1 answer
51 views

How to get all attachment image from post ?? WordPress

I just want to get all atachment image from post with Alt, description, title, size, resotution and how to add DOWNLOAD button? i want to create image downloading website on wordpress for example LINK ...
user avatar
  • 5
0 votes
2 answers
44 views

Get all image in media Gallery with alt/title?

Is there a way to fetch the ALT/TITLE of ALL images in the media gallery? I think this would be an easy way for a website to have a Pictures page that just pulls all of the images from the media ...
user avatar
  • 5
0 votes
1 answer
61 views

Use rich text editor in 'Edit Media', for attachment media description

I have the following in my functions.php: add_filter( 'wp_editor_settings', function( $settings ){ if( get_post_type() == 'attachment'){ $settings = [ 'wpautop' => true, '...
user avatar
  • 133
0 votes
0 answers
42 views

Unable to delete related media attachments with deleted post

I want to delete the post attachments too from the 'Media" panel once a custom post is deleted. The post itself gets deleted well, but its media still remains in the wordpress "media" ...
user avatar
0 votes
1 answer
34 views

Auto delete content in specific folder inside media library

I am looking for solution to auto delete images (jpg, gif, png -content in general) inside a specific folder (folderx) INSIDE the uploads/months folders (customization intended for future folderx --...
user avatar
0 votes
0 answers
26 views

Enable Gutenberg for attachment edit page

I'm trying to get Gutenberg working when you edit media details (attachment post type). This is what I have so far: add_filter( 'register_post_type_args', function( $args, $post_type ){ if ( '...
user avatar
  • 133
0 votes
0 answers
24 views

How to display a link to the post where an image is attached on the attachment template or attachment single page?

When viewing a single image or attachment, how can I display a link to a post where that image or attachment is attached? This is similar to the link in the edit media in the dashboard tjat is called &...
user avatar
  • 149
0 votes
1 answer
37 views

how to get random media id from media gallery

I tried to get random media id from wordpress media gallery using this: $image_ids = get_posts( array( 'post_type' => 'attachment', 'post_mime_type' => '...
user avatar
  • 107
1 vote
0 answers
82 views

Add the description field on the attached media

Well, we want to add the description field on the attached media under the post edit page. I have attached an image for reference. Explanation: Under posts, after adding an attachment if we click on ...
user avatar
0 votes
0 answers
45 views

How can i set media attachments to the author of the post or page for already existed posts with attachments

I have been uploading posts for multiple authors in my site and the attachements (photos) are registered all in my account. Is there a way to set the attachements to have the author of the post ? I ...
user avatar
0 votes
2 answers
127 views

How do I update attachment urls after changing site domain

I recently moved my site from https://subdomain.example.com to https://example.com. Now all my attachments still point to https://subdomain.example.com/wp-content/uploads/2021/04/file.mp3 even though ...
user avatar
1 vote
0 answers
32 views

How to change File URL in file uploaded to s3 compatible storage with self written plugin [closed]

I'm trying to write a plugin that uploads files directly to an S3 storage and allows to downloads them like files directly on the server. The main page of the plugin contains the following code for ...
user avatar
0 votes
1 answer
52 views

How to add a default predefined thumbnail when creating a brand new post?

I'm making a plugin that has a custom post type and I need to add predefined content. I used filters default_title and default_content for the title and content but I can't find how I can add an ...
user avatar
0 votes
1 answer
33 views

How to add a custom field for image in "Text and Full Image(text right)" layout?

I need add another image in the standard "Text and Full Image(text right) layout" in WordPress. This layout by default has a field for an image. I located the php file that renders this ...
user avatar
0 votes
1 answer
47 views

WP_Query for Attachments not working as expected

I have a function to retrieve a random set of pictures according to the category. This has been working when I set up the website last year. Now I tested the site today and found out that none of my ...
user avatar
0 votes
2 answers
27 views

Get all post embedded images

i want to get a post embedded images but the only methods i see over the internet are $attachments = get_posts(array( 'post_parent' => get_the_ID(), 'post_type'...
user avatar
  • 113
1 vote
2 answers
139 views

Audio file's length (duration) is missing from Attachment Details in Media Library [closed]

I'm uploading a different mp3 file to each post as an attachment and using wp_get_attachment_metadata() to print the duration of the mp3 file. Sometimes the response from wp_get_attachment_metadata() ...
user avatar
1 vote
1 answer
15 views

How can I get the number of custom post type posts that have a specific attachment image set?

I'm currently using this to filter out only posts that have a specific custom image attachment field value. But it's returning 0. I used this method for other custom fields and it worked great. Is ...
user avatar
0 votes
1 answer
165 views

How do I assign an attachment to a post using only the REST API?

I am able to create a new post by sending a request with cURL against the REST API. That works fine. I am also able to upload files into the media library with cURL via the REST API. The uploaded ...
user avatar
0 votes
1 answer
210 views

Shortcode for Custom Field of Media Attachment (to use with Featured Images)

I'm using ACF (Advance Custom Fields) for Media Uploads to store location information about photos. When I set a post Featured Image to a photo that has this extra field, I'd like to output the ...
user avatar
0 votes
1 answer
23 views

How do I add a medium to the Wordpress database with my own plugin?

I wrote a plugin that accepts files via Wordpress and saves them outside of the server. Now I would like to save the metadata as normal in Wordpress, as if the file were on the server. Is there a hook ...
user avatar
0 votes
1 answer
159 views

WordPress Attachment Page URL Rewrite!

I am creating a gallery site using FooGallery and having the individual images open in the attachment page. I tried a bunch of codes from here to rewrite the attachment urls from ?attachment_id=8184 ...
user avatar
1 vote
0 answers
33 views

How can I use var php with javascript to build custom page? [closed]

is variable increment in $post_per_page = 10 if click on button next I can increase $Post_per_page = by_call <button type="button" value="increment++" >Increment </button&...
user avatar
0 votes
1 answer
25 views

Add a word to the first // wp_get_attachment_url // as the subdomain name

We use this code to display the link ... $mp3Link = wp_get_attachment_url($mp3_file_id); <a class="w3-black" href="'.$mp3Link.'" rel="nofollow" >mp3</a> It ...
user avatar
  • 3

1
2 3 4 5
20