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.

learn more… | top users | synonyms

3
votes
1answer
2k views

Programatically creating image attachments from local URLs and setting featured image

I'm currently working on importing an MovableType blog into WordPress. The blog has several thousand posts, and each post has an image associated with it. The export file contains references to each ...
3
votes
1answer
72 views

Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?

I am looking for solution to auto delete images of old posts in WordPress site. I want to hold images of current 50 posts, others should be deleted automatically. It can be function to delete on time ...
3
votes
2answers
1k views

wp_generate_attachment_metadata gives me an empty array

I have a custom post type and a metabox with a file input. I can insert the attachment, but I can't update the attachment metadata and I don't know how to fix it because I don't receive any error. ...
3
votes
1answer
920 views

delete attachment from front end

logged in as admin and trying to code that deletes posts to delete an attachment. got, <?php if (current_user_can('edit_post', $attachment->ID)) echo "<a href='" . ...
3
votes
2answers
491 views

how to test for attached image

I am trying to find out whether or not a post has images. If it does, I then want to know if a featured image was specified for the thumbnail - if not, the get_thumb() function will assign an image ...
3
votes
1answer
252 views

On Multisite: Loop to Show First Four Images of Recent Posts Across Network

I would like to display the first four images from posts across a WordPress network. In Otto's image gallery tutorial he recommended using the following to get images from recent posts. Query ...
3
votes
1answer
1k views

Uploading Multiple Attachments From Front-End With A Description

I am working on a Wordpress site that has a custom front-end submission form for adding in a post of content type, 'sketchpad'. The form has a section that allows you to upload multiple images with a ...
3
votes
3answers
2k views

Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?

Is there a built-in feature or plugin that allows you to attach a document to a post or page such that the actual attachment file is one thing (eg a PDF) but the thumbnail images are another (eg a ...
3
votes
2answers
796 views

remove missing image attachments

Best way to programatically remove attachments that are missing images? I ask because after using a caching plugin, I have images that have been input in the database as attachments that don't ...
3
votes
1answer
262 views

Add a YouTube or Vimeo video as a post attachment?

I'm developing a gallery plugin and I was wondering if I could add a YouTube and Vimeo "embed" option to the media uploader to be able to add YouTube and Vimeo videos as attachments to a post instead ...
3
votes
1answer
147 views

get post attachments of a particular size

Is there a good way to know if a post has an image attachment of a particular size? I'm trying to fetch 5 random posts, but I only want results that have image attachments with a (custom) size of ...
3
votes
1answer
111 views

WordPress comment count to include attachment comments

How can I make the comment count on a post on my index page include comments that have been made on, in my case, individual gallery pictures that are included in the post? It seems that comments made ...
3
votes
3answers
482 views

List most recent image uploads, but only for specific custom post type

I can get a list of the most recent image attachments like so: $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => $number, 'post_mime_type' => ...
2
votes
4answers
4k views

using upload image with media_handle_upload .. but !

I'm tring to upload image in wordpress by using some function .. I found the way to upload images but there are one problem .. when the user upload his image , wordpress create more than one image ...
2
votes
2answers
4k views

Add_Filter example for wp_get_attachment_link

Let me preface by saying I don't really understand Add_Filter, but I think that I want to be using it here. If not please let me know. I want to modify wp_get_attachment_link so that the link url ...
2
votes
1answer
693 views

Doubled titles when using All in One SEO with custom template

I created a separate template, attachment.php, for displaying image attachments. It's relatively simple; basically a stripped down version of single.php. Everything is working great except that when ...
2
votes
2answers
76 views

Use an attachment in multiple posts

I have an attachment in a post and I want to attach it to another post without detaching it from the first post, using the WP API.
2
votes
3answers
683 views

How can you determine whether an image is merely attached or has actually been inserted into a post?

Bear with me. I promise there's a question when I'm done :) In WordPress, you can upload images while editing a post and have the option to insert them into the content (or not). Regardless, the ...
2
votes
1answer
227 views

query attachments of parent page if attachments of current page are smaller than …

I'm using WPQuery and get_children($query_images_args) to query attachments from the current page. If the current page has no attachments assigned I'm querying the images of the parent page. This ...
2
votes
4answers
2k views

get attachments for all posts of particular post type

I'm making a widget that shows a set of images from recent custom posts. I want to run the following query: SELECT p.* FROM wp_posts p WHERE post_type='attachment' AND post_mime_type LIKE 'image%' ...
2
votes
3answers
299 views

Limit amount of results returned

How can I limit the amount of results returned? $images = $wpdb->get_col(" SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND ID in ($meta) ORDER BY menu_order ASC ...
2
votes
1answer
1k views

get_the_post_thumbnail() doesn't taking style attribute

This seems to be an easy one but its giving me quite a hard time. get_the_post_thumbnail() suppose to take attribute as an array. Well, everything working right but when i pass style attr its doesn't ...
2
votes
2answers
1k views

sanitize attachment filename

I'm looking for a way to sanitize the filename of user uploaded attachments. I thought that wordpress already did it but I faced preblems after an user uploaded an attachment containing a '°' . That ...
2
votes
1answer
783 views

Saving Custom Field in Attachment Window in WordPress 3.5

I'm using the code below to add a custom text field in WP 3.5 Attachment Window (from this question # Expanding new Media Uploader in WordPress 3.5) ... add_filter( 'attachment_fields_to_edit', ...
2
votes
2answers
2k views

How can I hide media library images from general users?

As an admin I really like the features and functionality of the WordPress 3.5 media manager. With a multi-user site however all users can see all images in the media library - whether uploaded by ...
2
votes
1answer
1k views

what types of order can I pass to get_posts() via orderby?

Here describes get_posts() function. I would like to know what types of order can I pass to get_posts? in WP admin, I can see menu order, title, date, random and ...
2
votes
2answers
498 views

add_rewrite_rule and attachment_id

Im trying to add a rewrite rule to make this mysite/?attachment_id=106 view like this mysite/series/106 Ive looked evetywhere in this site and others and its very confuse because there are lots of ...
2
votes
2answers
336 views

Converting a simple plugin to be placed inside of functions.php

First off, I know it's better practice to use plugins separately than to integrate them in functions.php but this is for a theme framework that will be deployed to multiple sites and it will be easier ...
2
votes
1answer
1k views

Custom function to rearrange attachments when creating posts – Almost there

I'm having some trouble with a custom thing I'm doing. I've implented a custom image uploader into a metabox in a custom post type. Now I'm trying to work out a way that will let me reorder the ...
2
votes
3answers
3k views

How to find attachment ID for first image in a post

I am using a plugin to forward photo posts from wordpress to a tumblr blog. I have the following code: //post blog to tumblr function postBlogTumblr($postID) { $URLServer = ...
2
votes
1answer
2k views

Retrieving a custom link on an attachment

I wanted to link images in a gallery to a custom URL. I know I could add an extra field and do it this way I found this ticket on Trac, though, that modifies the "Link URL" field to accept custom ...
2
votes
2answers
2k views

How to delete post attachments when jQuery is used with a click event on the delete link

I think I'm on the right track with what I need to do, at least for doing one of the ways it could be done. I'm not really sure though, I could be way off for all I know. This is part of the code I ...
2
votes
2answers
391 views

Importing media medium setting image gallery / image attachments

I have recently imported an image gallery to a clean WP install as I am deploying the site to a live domain. I have imported the posts but the images use the medium size for attachements. I would ...
2
votes
1answer
303 views

Delete attachments from Front end

I am trying to make a simple media manager on the front end of my posts, as my site will have many authors. I want to give them the ability to delete any picture attachments that they have uploaded to ...
2
votes
1answer
143 views

Rename attachments during upload

Here's the function I use for WP to rename images during upload on the fly and set the image's filename to match the post slug. function wpsx_5505_modify_uploaded_file_names($arr) { // Get the ...
2
votes
2answers
6k views

How to get attachment caption (get_the_excerpt gives parent post excerpt) ?

I am displaying the attachments on the parent post page with this code : $args = array('post_type' => 'attachment', 'post_mime_type' => 'image', 'order'=> 'ASC', 'numberposts' => ...
2
votes
2answers
2k views

How to replace “wp-content/blogs.dir” with “media” for attachment permalinks?

How to replace "wp-content/blogs.dir" with "media" for attachment permalinks in a multisite environment? This is how links look now: ...
2
votes
2answers
506 views

Best way to programatically add “rel” attributes to page and post images

For single posts and pages, I would like to add certain rel attributes to all the images on the contained therein added with the "Add Image" functionality on the edit screen. The attribute would be ...
2
votes
1answer
28 views

Set attached to state

In the media library every attachment post has an "Attached to" column. I've developed a plugin that adds author profile and a facebook like banner image. I now discovered that the attachment posts, ...
2
votes
2answers
220 views

Correct Way To Show Custom Taxonomy for Image Attachments on Template File

I've created a custom taxonomy called imagetags using the following code: // Register Custom Taxonomy function custom_imagetags_taxonomy() { $labels = array( 'name' => _x( ...
2
votes
1answer
494 views

Adding class to next/prev image link in attachment.php

Is it possible to add a class or ID to next/prev image links in attachment.php? I tried like this but it didn't work: <?php next_image_link( false, 'Next', array('class' => 'next')); ?>
2
votes
1answer
523 views

Get attachments (get_posts) and WP 3.5 new uploader

I'm using get_posts() to get attachments from the post and use it in the slider. The issue is new uploader doesn't have that "Gallery" tab which was perfectly suitable for this. It also seems to be ...
2
votes
1answer
636 views

query attachment images … if no attachments -> get attachments of parent page?

I use this to query all attachments of the current page or post I'm on … $query_images_args = array( 'post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => ...
2
votes
1answer
482 views

Replacing with(out) regex link to attachment by links to files

I tried to do it myself but I have really hard time with Regex (regex is hell. I just don"t understand). Anyway, I think this would be usefull to some people. The context is that we use a plugin to ...
2
votes
1answer
249 views

How to set author for post AND post attachments

I have multiple author accounts on one of my WordPress installs. Often I will create a post, and set the author to be a different account. However, when I upload images into that post, their ...
2
votes
2answers
520 views

Getting ID from ajax response of async-upload.php

Its a wordpress+jQuery question. Can't post it on stackoverflow because i believe it involves wordpress knowledge too. What I am trying to achieve: I am attaching the wordpress async media uploader ...
2
votes
1answer
329 views

Set WordPress Featured Image For All Post Slugs Matching Image File Name in Specified Directory

I have a bunch of old posts on a blog that I would like to assign a featured image to. I have retrieved all the images I would like to use for each post. I saved each image file name after the slug ...
2
votes
1answer
761 views

How to add attachment without uploading?

When save post, I made dir in wp_uploads_dir, and copied 2 files and one folder in this dir. Now I want to do the WP_insert_attatchment process to make the 2 files as attachements. How can I do it? ...
2
votes
2answers
599 views

Display info from custom fields in all images' HTML

Okay, I've been working on this all day and can't find the solution anywhere. I've created a custom field within the image upload screen (info first found here). The field stores the name of a ...
2
votes
3answers
1k views

Change image link: wp_get_attachment_link

Can anyone help me filter wp_get_attachment_link so that a particular occurence of it links to the 'medium' or other size image rather than the full size. I have the following in a page template: ...