Skip to content

Instantly share code, notes, and snippets.

@sudipto-me
Created May 24, 2019 09:08
Show Gist options
  • Save sudipto-me/a9a862ea67531cf46e81b95dd2723912 to your computer and use it in GitHub Desktop.
Save sudipto-me/a9a862ea67531cf46e81b95dd2723912 to your computer and use it in GitHub Desktop.
Get total attachment image count of a wordpress site media from functions file.
/*
*Add this code to your theme's function file or site-specific plugins
*/
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;
}
/*
* Now call this function where you need to show the img count
*/
echo img_count();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment