Change image link: wp_get_attachment_link

I think I’ve answered my own question sort of…. As I was using a child theme of Hybrid I activated the cleaner gallery extension in the functions.php file: add_theme_support( ‘cleaner-gallery’ ); Then, based on the topic here I created my own filter: add_filter( ‘cleaner_gallery_image’, ‘my_gallery_image’, 10, 4 ); function my_gallery_image( $image, $id, $attr, $instance ) … Read more

get post attachments of a particular size

The image attachment type is stored in the postmeta table in the _wp_attachment_metadata meta key. The data is serialized, so it can’t be filtered on. But you could use a meta_query in your query: $images = get_posts( array( ‘post_type’ => ‘attachment’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘_wp_attachment_metadata’, ‘value’ … Read more

how to test for attached image

function has_image_attachment($post_id) { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image/jpeg’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post_id ); $attachments = get_posts($args); if(is_array($attachments) && count($attachments) > 0) { //Has image attachments return true; } else { return false; } }

Creating a multi-file upload form on the front end for attachments

This may not be the most elegant way to do it (I’m not sure if overwriting the $_FILES global is even allowed) but this seems to work: global $post; if ($_FILES) { $files = $_FILES[‘upload_attachment’]; foreach ($files[‘name’] as $key => $value) { if ($files[‘name’][$key]) { $file = array( ‘name’ => $files[‘name’][$key], ‘type’ => $files[‘type’][$key], ‘tmp_name’ … Read more

Add column for attachment file size

Working code: // Add custom column with file size info to attachment page add_filter( ‘manage_media_columns’, ‘bb2_manage_media_columns’, 10, 2 ); function bb2_manage_media_columns( $columns ) { $columns[‘filesize’] = __( ‘Storlek’, ‘bb2’ ); return $columns; } add_action( ‘manage_media_custom_column’, ‘bb2_manage_media_custom_column’, 10, 2 ); function bb2_manage_media_custom_column( $column_name, $id ) { switch ( $column_name ) { case ‘filesize’ : $bytes = … Read more

Delete attachments from Front end

You can do it via ajax, first, let’s change your current function to this: <?php $args = array( ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’, ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’, ‘post_status’ => null, ‘numberposts’ => -1, ); $images = get_posts( $args ); $imagenum=0; foreach($images as $image): $imagenum++; ?> <div style=”width:110px; float:left;”> <?php … Read more

How can I display custom fields value from attachment media?

Use these: get_post_meta($attachment->ID, ‘_title_en’, true); get_post_meta($attachment->ID, ‘_description_en’, true); get_post_meta($attachment->ID, ‘_title_es’, true); get_post_meta($attachment->ID, ‘_description_es’, true); See if you need to use the _ prefix: Creating Custom Fields for Attachments in WordPress Also: Function Reference/get post meta

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)