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, // Get data from the current post ‘post_type’ => ‘attachment’, // Only bring back attachments ‘post_mime_type’ => ‘image’, // Only bring back attachments … Read more

Programmatically adding images to media library

I am trying to programmatically add multiple images to media library, I uploaded the images to wp-content/uploads, now I try to use wp_insert_attachement. Here’s the code, however it’s not working as expected, I think metadata is not properly generated, I can see the files in media library, but without a thumbnail, also if I edit … Read more

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 attachments from within the media modal to a post of any post type, it establishes a relationship where the post ID is the parent of the attachment ID, … Read more

How to get image title/alt attribute?

In my white theme, there is no alt attribute configured for the home slider post. I added the alt text for the image through the media library interface. I added the following code to display the alt text/attribute. But it does not display: <img class=”homepage-slider_image” src=”http://www.blabla.com/wp-content/uploads/2013/06/cms-website4-1800×800.jpg” alt=”” /> Here is the code: <?php $image = … Read more

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’ => $main_post_id ); $attachments = get_posts($args); foreach ($attachments as $attachment) { the_attachment_link($attachment->ID, false); } but after the link I need to display the file’s size. How can I do this? I’m guessing … Read more