How to Display Post Attachment Count In Admin Column

Add Tool

Display Post Attachment Count In Admin Column


Sometimes you have some posts with multiple attachments and it would be helpful to see a count of the total media attached to a post. Adding this snippet to the functions.php of your WordPress template will display the post attachment count in a custom admin column. Display post attachment count in admin column is a great function to add to your theme if you add a lot of images to your posts.

add_filter('manage_posts_columns', 'posts_columns_attachment_count', 5);
add_action('manage_posts_custom_column', 'posts_custom_columns_attachment_count', 5, 2);
function posts_columns_attachment_count($defaults){
    $defaults['wps_post_attachments'] = __('Att');
    return $defaults;
}
function posts_custom_columns_attachment_count($column_name, $id){
  if($column_name === 'wps_post_attachments'){
  $attachments = get_children(array('post_parent'=>$id));
  $count = count($attachments);
  if($count !=0){echo $count;}
    }
}

Source


Tags: count media attachments, Post Attachment Count, Admin Column, WordPress Development, wp media attachments
Payza

About Masum Billah

Display Post Attachment Count In Admin Column 1stWebSuite website seo tool is a free website ranking tool site provides a lot of on page and off page seo useful tools for you. On this site, we have a large number of website ranking tools


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: How to Display Post Attachment Count In Admin Column


adf.ly