29
Jul
Display Post attachment count on Admin side
- Category:
- Wordpress

Posted On : July 29, 2013
| No Comment
Suppose you have used many attachments in your posts, and want to know the count of each posts attachments on Admin side posts list, than, use below simple code in your theme’s function.php file.
Code :
View Code PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //Used to create any column on posts list page admin side add_filter('manage_posts_columns', 'posts_attachment_count'); add_action('manage_posts_custom_column', 'attachment_count', 5, 2); function posts_attachment_count($defaults){ //enter column name $defaults[‘columnname'] = __('Attachment'); return $defaults; } function attachment_count($column_name, $id){ if($column_name === ‘columnname’){ $attachments = get_children(array('post_parent'=>$id)); $count = count($attachments); if($count !=0){echo $count;} } } |
Screenshot
- Tags: