I am trying to add a column in the edit post screen that shows any attached media. I found this code to do it with tags, but don’t know how to change it to do Media attachments instead.
//add media column to edit post screen
add_action('media_buttons_context','zg_post_buttons');
function add_tag_column($posts_columns) {
// Add a new column
$posts_columns['att_tag'] = _x('Tags', 'column name');
return $posts_columns;
}
function manage_attachment_tag_column($column_name, $id) {
switch($column_name) {
case 'att_tag':
$tagparent = "upload.php?";
$tags = get_the_tags();
if ( !empty( $tags ) ) {
$out = array();
foreach ( $tags as $c )
$out[] = "<a href='".$tagparent."tag=$c->slug'> " .
esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display')) .
"</a>";
echo join( ', ', $out );
} else {
_e('No Tags');
}
break;
default:
break;
}
you can create a column of post_thumbnail like so:
and to add this column to custom post type just add your post type to
and and action and filter hooks
Hope this helps