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

Programatically creating image attachments from local URLs and setting featured image

Answers: Is post_guid the image location reference? Or is the path to the image stored somewhere else? $post->guid is the record in a post which holds the URL for your attachment. Where is featured image set? featured image is saved as post meta so use update_post_meta() once you have the attachment id: update_post_meta( $post->ID, ‘_thumbnail_id’, … 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

Add an image gallery to a custom post type?

When you just have raw image files, that you want to assign to a post, wp_insert_attachment will do the job. With attachments already present in your database you can use wp_update_post to set the attachment’s post_parent. Like this: wp_update_post( array( ‘ID’ => $attachment_id, ‘post_parent’ => $parent_post_id, )); To recieve a post’s attachments you can use … 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

Retrieving a custom link on an attachment

On the Trac ticket you’ve linked at the bottom there is a solution to make it work function _save_attachment_url($post, $attachment) { if ( isset($attachment[‘url’]) ) update_post_meta( $post[‘ID’], ‘_wp_attachment_url’, esc_url_raw($attachment[‘url’]) ); return $post; } add_filter(‘attachment_fields_to_save’, ‘_save_attachment_url’, 10, 2); function _replace_attachment_url($form_fields, $post) { if ( isset($form_fields[‘url’][‘html’]) ) { $url = get_post_meta( $post->ID, ‘_wp_attachment_url’, true ); if ( … Read more

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