How to Show Total Images Uploaded in WordPress

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

code to count total uploaded image in WordPress

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

To count total Image uploaded in WordPress, Just copy Paste the following code inside your functions.pho 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.

<?php echo img_count(); ?>

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>