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
700 views

Remove “From computer” media tab for posts with existing attachments?

On editing the attachments of a post whith at least one attachment previously uploaded, how do I remove the From computer tab and redirect to the Gallery tab? This is my current code: ...
3
votes
2answers
35 views

Check if post has attachments (not image)

Need to do a check if post has attachments that are not images. I haven't seen this anywhere - thoughts?
3
votes
1answer
358 views

Bulk term assignment for attachment taxonomies

I've created a custom taxonomy for attachments. Everything ok, but now I want the ability to bulk assign its terms to attachments using the default wordpress media admin ('upload.php') bulk actions. ...
3
votes
2answers
3k views

Set Featured Image Front Frontend Form

I have been struggling for days to figure this one out. I have successfully implemented a form to submit posts from the front end of my site. ButI can't figure out how to make the image uploads work. ...
3
votes
3answers
7k 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' => ...
3
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 ...
3
votes
3answers
4k 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 = ...
3
votes
1answer
2k views

media_sideload_image generates blank?

I'm creating a custom post form that is supposed to take an external image and uploads it to the media library and attach it to that post. This should be possible by using media_sideload_image, but ...
3
votes
2answers
939 views

Function to call the attachment image from post

Hey everyone, I can't se the image of the post (it is attached through gravity form as a post-image) with this function I see the missing image icon with the title and the working link but no ...
3
votes
1answer
287 views

How do I delete all generated images from my server except those currently used in posts

I have a new set of image sizes for my site's in-development theme. My server is filled with old image sizes, most of which have never been used. You've heard this one before, right? The Question How ...
3
votes
2answers
3k views

Password protect some uploaded files, so only logged-in users can view them

I would like to protect some uploaded files, so that they are not publicly accessible (they are not accessible without a login). I'm uploading some PDF files, and I'd like to mark some of them as ...
3
votes
2answers
2k 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
2answers
3k views

Automatic image renaming based on title

Is there a plugin or a "hack" that can help me do this? I have spent hours try to figure this out so I would greatly appreciate nay help. I have WP 3.1 running php5 Thanks! eg.: ...
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
214 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
382 views

How to set a default meta value for custom field

I have setup a custom meta_key for attachments. Since it is a radio button with Yes/No options, and the default value is always Yes, I need that this default value is saved into the db when the ...
3
votes
1answer
1k 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
530 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
281 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
3k 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
1k 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
2answers
564 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
198 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
119 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 ...
2
votes
4answers
5k 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
4answers
8k views

How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?

I am trying to retrieve all the images from the Gallery of a page in the order they are set in the backend. So far I have: $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query( ...
2
votes
4answers
28k views

How to Fix HTTP Error When Uploading Images?

I am using WordPress 3.4.1 on Ubuntu 12.04 using Apache and PHP 5.3.X When I login to the dashboard and add a new post. Then try uploading an image to set as a featured image, I get a red box with a ...
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
741 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
1answer
608 views

Change the Permalink for wordpress attachment

My attachments are currently rewritten from http://localhost/?attachment_id=3 to http://localhost/images/image-title using @Bainternet's answer here. $new_rules['images/(\d*)$'] = ...
2
votes
2answers
3k 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
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
3answers
789 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
1k 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
1answer
283 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
3k 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
1answer
2k views

media_sideload_image file name?

I'm using media_sideload_image to download images from the web and store them. However, the problem is that the ones from youtube are always called "hqdefault.jpg", which means that it will override ...
2
votes
3answers
390 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
401 views

How to grab the first two image attachments from a post?

I am grabbing an image that is uploaded to that post working with this function: wp_get_attachment_image_src <?php $images = get_children( array( 'post_parent' => $post->ID, ...
2
votes
1answer
2k 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
2answers
840 views

Correctly delete posts with meta and attachments [duplicate]

I am having an overview of custom post types. These have custom tax and also an attachment. In my overview I need to provide links to delete the entries. With that I also need to delete the ...
2
votes
1answer
2k 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
1answer
828 views

Link Featured Thumb to Attachment Page, If Possible

Are featured thumbs uploaded the same as other images and have their own attachment post url? I'm trying to utilize the 3.0+ post formats and am using the featured image when creating a post under ...
2
votes
2answers
466 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
2answers
3k views

Find the post an attachment is attached to

I have a list of attachment IDs which are built using this array: $all_images = get_posts( array( 'post_type' => 'attachment', 'numberposts' => -1, ) ); Is it possible to take the image ID ...
2
votes
2answers
2k views

delete post also attachments

I am trying to delete a post with its all attachments. This is the function that i came up with right now; function remove_post(){ if(isset($_POST['post_id']) && ...
2
votes
1answer
8k views

how to get original image using wp_get_attachment_image_src

I want to get the original image with the same width and height as uploaded. My original image is 630*370. Using the following function call I get a thumbnail sized at 630*198. ...
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 ...