×

How to Count Total Images Uploaded in WordPress

count total uploaded image

Images are integral part of  any website. Photo blogging now a days becoming more and more popular among event bloggers. New and lazy bloggers also do not want to write articles on every day but they want a constant money from their blog all the way. Right ?

count total uploaded image

Wallpaper Based weblog is such a web site and while working on our Abhishek Wallpaper Theme, We were forced to find out how many Wallpapers/ Photos, we have uploaded on our website.

To count total Image uploaded in WordPress, Just copy-paste the following code inside your functions.php file

/*---count total number of images in image gallery---*/
function img_count(){
$query_img_args = array(
'post_type' => 'attachment',
'post_mime_type' =>array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
),
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_img = new WP_Query( $query_img_args );
echo $query_img->post_count;
}

The above code will count total no. of image files available as an attachment. Now its time to use this function in your single.php file or any other file wherever you want to use.

Just copy-paste the following code to display total no. of uploaded Images.

  

Note: If you want to count any other type of uploaded file, Just change the post_mime_type and fire this query.

Related Posts

Leave a Reply

Your email address will not be published.