Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to display the description of each file on the media library browser screen. I've found some code that adds a filename column, but I'm trying to modify it so that it will display the description field instead of the filename. I'm not quite sure of how to do this. The description column displays, but doesn't actually show the description data for each file. I think I'm getting hung up on this line:

echo substr(strrchr($meta['attachment_content'], '/' ), 1);

but it's possible that there are other issues.

Below is the full code:

function description_column($cols) {
    $cols["description"] = "Description";
    return $cols;
}

function description_value($column_name, $id) {
    $meta = wp_get_attachment_metadata($id);
    echo substr(strrchr($meta['attachment_content'], '/' ), 1);
}

function description_column_sortable($cols) {
    $cols["description"] = "name";
    return $cols;
} 

function hook_new_media_columns() {
    add_filter('manage_media_columns', 'description_column');
    add_action('manage_media_custom_column', 'description_value', 10, 2);
    add_filter('manage_upload_sortable_columns', 'description_column_sortable');
}

add_action('admin_init', 'hook_new_media_columns');

Thanks for your help!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I think I'm getting hung up on this line:

echo substr(strrchr($meta['attachment_content'], '/' ), 1);

Yep! Try this version of the description_value function:

function description_value($column_name, $id) {
    echo  get_the_content($id);
}

Media items are posts of the type attachment. The description is stored in the post_content property of the post object. You can see all of the fields by doing a print_r( get_post( $id ) ); just in case you wanted to make some other columns. By the way, wp_get_attachment_metadata will give you access to the EXIF data of the image, which I don't think you want here.

share|improve this answer
    
Thank you! And thanks for the extra info, that will definitely come in handy. –  Sean Henderson Nov 8 '13 at 4:09
    
No prob, glad I could help! –  goto10 Nov 8 '13 at 4:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.