Loop issues when creating custom query for media uploader

I’m not entirely sure why the get_posts() function works instead of creating a new instance of WP_QUERY. From what I understand about how WordPress queries work, get_posts() is actually creating it’s own instance of WP_QUERY anyhow. Either way, here is the solution that I’m using currently. <?php //GET THE PHOTOGRAPHERS $args = array( ‘post_type’ => … Read more

Custom attachment field dissapearing

I figured it out. In an effort to organize/optimize my actions and filters, there are a bunch that I only call on certain pages, using WordPress’ global $pagenow variable. I was only calling the “attachment_fields_to_edit” filter for media-upload.php, async-upload.php, and media-new.php, which apparently isn’t a valid way to do this with the new uploader. I … Read more

Custom classes for attachments

Just add the following code in functions.php file of your theme which will add your custom added classes to images when you will insert it into post editor. function add_image_class($html, $id, $caption, $title, $align, $url, $size, $alt=”” ){ $classes = get_post_meta( $id, ‘classes’, true ); if ( preg_match(‘/<img.*? class=”.*?”>/’, $html) ) { $html = preg_replace(‘/(<img.*? … Read more

Adding fields to attachment – only shows when inserting new attachments

Okay I think I have it, you need to add a matching filter to attachment_fields_to_save to save the new field (say as post meta to the attachment.) add_filter( ‘attachment_fields_to_save’, ‘save_some_custom_field’, 10, 2 ); function save_some_custom_field($post, $attachment) { $attachid = $post[‘ID’]; // yes this is actually an array here update_post_meta($attachid,’someCustom’,$attachment[‘someCustom’]); } Then you would add to … Read more

Custom field in media library not saving, selected() function not adding “selected” to select list input type

As per outlined in the comments, by fixing a typo in my save function, and setting the third parameter in get_post_meta() to true, and false in selected() it worked liked a charm. Thanks everyone! Here’s the working code in case anyone is trying to add a select list custom field to their media manager: /* … Read more

Get all image in media Gallery with alt/title?

<?php /* * Template Name: Gallery Page */ $query_images_args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => – 1, ); $query_images = new WP_Query( $query_images_args ); ?> <?php get_header();?> <div class=”main”> <div class=”row”> <?php foreach ( $query_images->posts as $image ) {?> <div class=”col-md-3″> <?php echo wp_get_attachment_image( $image->ID,’thumbnail’ );?> </div> <?php … Read more