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

17
votes
1answer
4k views

How to manage attachment relationships for specific posts in WP 3.5+

In WordPress 3.5, media management has changed entirely. Also, relating attachments to specific posts is (I believe) basically only being done for backward compatibility. Therefore, after uploading ...
12
votes
2answers
5k views

Creating an Image-Centric Custom Post Type?

Does anyone have any tips for creating an image-centric custom post type? To elaborate, my blog has rotating header images, shown below: The two images in the top left are randomized, and exist as ...
12
votes
5answers
5k views

Can I add a Category Metabox to attachment?

I am using register_taxonomy_for_object_type() to add the Category taxonomy field to Media uploads (attachments). I'm using this code to do so: add_action('init', 'reg_tax'); function reg_tax() { ...
12
votes
2answers
3k views

Turn a URL into an Attachment / Post ID

Is there any way I can take a URL of an image and find the attachment or post id of that image in the database? Here is the situation: I'm in a loop going over all the 'img' tags that are surrounded ...
11
votes
3answers
11k views

How do I get the size of an attachment file?

I'm using the following template code to display attachment links: $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => ...
11
votes
2answers
5k views

How does WP media uploader create the 3 different sized images, and how can I duplicate it

I have finally!! got this thing I've tried about 12 times to make and 12 different ways, but finally got it to work,... sort of. I made a custom metabox for uploading and attaching images to posts, ...
10
votes
2answers
20k views

How To Retrieve An Image Attachment's Alt Text?

I am using an attachment.php file to show large versions of images that have been clicked on elsewhere. I'd like to pull the image alt text as a caption under the image with javascript, but the alt ...
7
votes
3answers
7k views

Can I attach image to post without adding it to post?

another question about image. Can I add/attach images to post without adding it to post? The reason behind this is so that I can manipulate it whatever I want using API.
7
votes
4answers
5k views

Broken? WP_Query and “attachment” as a post type

I have a gallery attached to a page. On that page, I'm running the following query: $events_gallery = new WP_Query( // Start a new query for our videos array( 'post_parent' => $post->ID, // ...
6
votes
3answers
17k views

Submit post and upload image from front-end

I am trying to do something similar to the above question. I am trying to make users post and upload images from front-end. I have already done the post form and its working. I just followed and ...
6
votes
3answers
5k views

Getting Path To Uploaded Attachment Image After Upload

After you have uploaded an attachment in Wordpress using the media upload screen, is there a hook or filter I can run after the image has been uploaded where I can get the path to the uploaded image ...
6
votes
2answers
223 views

Is it possible to query all posts that don't have an attachment?

I want to get a list of all posts that don't have an attachment and delete them. This question takes about getting all posts that have an attachment, but I want the reverse of it. The brute force ...
6
votes
2answers
5k views

Attaching media to custom posts without editor

I'm creating a custom post type, "gallery", in which the admin should be able to upload images (these images would be attached to the post). The thing is that the "editor" meta box is disabled for ...
6
votes
1answer
6k views

Get all image from single page using this query

I'm having some trouble with this sample widget code. I want to get all images (Minus the post thumbnail) from a page called "Gallery" but for some reason this is pulling all uploaded images from the ...
6
votes
2answers
149 views

Is it possible to Schedule Attachments in Wordpress?

As it's fairly well known, it is possible to schedule Posts in Wordpress for publishing. Also Attachments are actually Posts (in the more internal, technical meaning). So the question that bothers ...
5
votes
4answers
3k views

Change attachment filename

Is there a function that allows me to change the filename of an attachment, based on the Attachment ID I have? Thanks! Dennis
5
votes
6answers
6k views

Disable image attachment links

Is there a way to disable image attachment links trought a filter in functions.php or something ? I know it's possible to do it manually when you add an image to a post but I want to disable this ...
5
votes
1answer
2k views

Programmatically get images by URL and save in uploads folder

I am involved in a large migration from another CMS to WordPress. We have a copy of the database and have worked out how to extract the content and programmatically create WordPress posts from it ...
5
votes
1answer
9k views

How to get attachment file name not attachment URL

I'm using this code to list the image attachments of a post: <select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;"> <option ...
5
votes
4answers
5k views

Get first image in a post

I am using this code directly from the codex. function echo_first_image ($postID) { $args = array( 'numberposts' => 1, 'order'=> 'ASC', 'post_mime_type' ...
5
votes
2answers
514 views

Delete Associated Media Upon Page Deletion

Note Use at your own risk, it is buggy and I have run across a couple instances where it would delete ALL attachments. Unsure why. Is it possible to delete media associated with a page when that ...
5
votes
3answers
4k views

How to use taxonomies on attachments with the new Media Library?

WordPress 3.5 changed the media management and now the Media Library edit screen uses the default post type UI. Taxonomies are very useful for WP installs with different users and attachments, giving ...
5
votes
1answer
2k views

Changing attachment urls?

How can I change the format of attachment page urls from /[post-url]/[attachment-name]/ to /media/[attachment-name]/? I understand that I can override the output of get_attachment_link via the ...
5
votes
1answer
2k views

Put the media uploader in a metabox

I find it very unnecessary to have an "add image" button that brings me to yet another screen that will let me upload content to my post. Ideally I would like to have a meta box with the option to ...
5
votes
1answer
3k views

simple solution for restricting access to (some) uploads/downloads

Initial Situation For a site I'm setting up I was looking into the whole field of securing uploads/downloads and restricting access to them based on user roles/capabilities. Of course I have read ...
5
votes
2answers
2k views

Expanding new Media Uploader in WordPress 3.5

In current version of WordPress it is quite easy to expand the attachments fields using attachment_fields_to_edit filter, but in latest WordPress 3.5 RC2 it's not working. We can expand it using ...
5
votes
1answer
4k views

remove links from images using functions.php

I am looking for a way to remove the attachment link from images in the post content. I would like to add this to the functions.php in my theme. I know you can disable this in the post on a per ...
5
votes
1answer
1k views

Trying to hide buttons from Attachment window

To simplify the Media Library layout to users when uploading an image, sometimes i hide the following fields: function myAttachmentFields($form_fields, $post) { if ( ...
5
votes
2answers
802 views

Are captions stored anywhere?

In regards to my previous question about shortcode captions, it doesn't appear to me that the actual text of a caption is stored anywhere other than in the post content within the shortcode itself. I ...
5
votes
1answer
1k views

Saving images from Gravity Forms repeatable File Upload as post attachments [closed]

I am trying to upload multiple images as attachments to a post using Gravity Forms and the Gravity Forms + Custom Post Types plugin. I have a repeatable File Upload field using the Gravity Forms ...
5
votes
1answer
281 views

Remove duplicate attachments

Here is the situation: I have an automated script that upload attachments and link each attachment to a specific post. By mistake, the script run multiple times and I have the following More than ...
5
votes
1answer
449 views

Edit image / Delete image link

There is a function in Wordpress that allows to display a "edit post" link if the user has sufficient rights. <?php edit_post_link( __( 'Edit' ), '<small class="edit-link">', ...
4
votes
1answer
8k views

Get all post attachments except featured image

$args = array( 'post_type' => 'attachment', 'numberposts' => null, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ...
4
votes
2answers
2k views

Delete original image - keep thumbnail?

I'm using a lot of thumbnails but never the original file. To save space, I'd like to prevent the original from being saved on disk but only keep a thumbnail of 100px. How can I do this? Thanks, ...
4
votes
2answers
110 views

Get all posts (of any post type) an attachment is used in

It's not easy to count the amount of posts an image is attached to - WordPress simply doesn't keep track of that. It just keeps track of the post an attachment was originally uploaded to (not ...
4
votes
2answers
1k views

How to cleanly delete attachment but retain original file?

wp_delete_attachment() is very comprehensive and wipes every trace of attachment from database and disk. Is there easy way to keep original file? Forking under another name is not an option, because ...
4
votes
1answer
64 views

How to add classes to images based on their categories?

I need to be able to: 1.) assign categories to images and 2.) add classes to all images that correspond to their assigned categories. I was able to add categories to images with the following: ...
4
votes
1answer
549 views

explode array within shortcode

This functions at the moment but it only returns the first value from the array. I've been struggling to echo, print, explode, or whatever the multiple custom field values that share the same key ...
4
votes
2answers
96 views

Unattaching unlinked images

As I understand default WP behavior: When you upload an image to a post and save it (as a draft or published post), the image becomes "attached" to the post. This can be double checked by going to ...
4
votes
1answer
82 views

complex restriction of items in media library

I have a need to limit items in the media library for users without a specific capability. There are a lot of examples out there for how to limit them to only items that a given user has uploaded, ...
4
votes
1answer
110 views

Theme Customiser Image Control

I'm aware that one can add a control to the theme customiser to add an image. This control returns an image URL however, and I need its attachment ID, not the image URL. Where can I intercept or ...
4
votes
1answer
1k views

How to paginate wordpress [gallery] shortcode?

I am using wordpress gallery shortcode [gallery] I was wondering if there is anyway to paginate them without using a plugin.
4
votes
2answers
921 views

How to get attachments for a specific post type?

I have this page where I am showing all post's attachments. This is the code: <?php $args = array( 'post_type' => 'attachment', 'post_status' => 'published', 'posts_per_page' ...
4
votes
3answers
548 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' => ...
3
votes
4answers
6k views

How to restrict access to uploaded files?

I have a restricted area on a website that can only be accessed by logged in users. For that I created a page template with a 'current_user_can()' condition. My problem is that the documents attached ...
3
votes
2answers
225 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.
3
votes
1answer
238 views

Show Post ID in “Find Posts or Pages” box in Media Library?

In the Media Library, when I go in to attach a media item to a post, I know I can use "Attach" to pull up the "Find Posts or Pages" pop up. This brings the following list of post title, date and ...
3
votes
2answers
661 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 ...
3
votes
1answer
1k views

Is it possible to query specific Wordpress Attachment files (.ppt & .pdf) and output them in a list?

The files are .ppt and .pdf files (not images). Will it be possible to query these types of attachments and output it in a unordered list?
3
votes
4answers
4k views

custom fields for attachments?

is it possible to add extra fields via the functions.php script for attachments in wordpress? Tried loads of examples but none seem to work. Worried an existing plugin might be affecting my attempts ...