Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14120 reviews 1680 hosting providers

Questions & Answers

I need to display the total number of images in my WP blog built?

Dec 10, 2012 by SunFun
Hi again…
Can anyone please tell me how to display the total number of images, all the images in my media library?
Appreciate your advice
thanks

1 Answer

0 votes
Dec 10, 2012 by expert
Try this to count the  total number of jpg, gif, and png images in your media library

Add  this code  to your the functions.php file
function img_cnt(){
        $query_img_args = array(
                'post_type' => 'attachment',
                'post_mime_type' =>array(
                                'png' => 'image/png',
                                'gif' => 'image/gif',
                    
                                'jpg|jpeg|jpe' => 'image/jpeg',
                                
                                ),
                'post_status' => 'inherit',
                'posts_per_page' => -1,
                );
        $query_img = new WP_Query( $query_img_args );
        echo $query_img->post_count;
}
Add this code in the location you want to display the count total.

<?
   img_cnt();
?>