Created
May 24, 2019 09:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*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