Quantcast
Channel: Wordpress API - Developer Code Book » wp tutorials
Viewing all articles
Browse latest Browse all 10

Show the image attachments count in Post list section

$
0
0

Many people wants to see the number of attachments which are used for posts. In Post list page people wants to see the number of image and other attachments. Using following code you will be able to see the attachment count in post list section.

You just need to copy and paste the following code into functions.php file.

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'] = __('Attached');
    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;}
    }
}

Show the image attachments in Post list section
Ref Url: http://wpsnipp.com/index.php/functions-php/display-post-attachment-count-in-admin-column/


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles



Latest Images