Skip to content

Instantly share code, notes, and snippets.

@jocastaneda
Created March 18, 2014 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jocastaneda/9631636 to your computer and use it in GitHub Desktop.
Save jocastaneda/9631636 to your computer and use it in GitHub Desktop.
Count how many galleries the post has and count all the images. Does require WP 3.6+
<?php
// Get all the galleries in the current post
$galleries = get_post_galleries( get_the_ID(), false );
// Count all the galleries
$total_gal = count( $galleries );
/**
* count all the images
* @param array $array The array needed
* @return int returns the number of images in the post
*/
function _get_total_images( $array ){
$key = 0;
$src = 0;
while ( $key < count( $array ) ){
$src += count( $array[$key]['src'] );
$key++;
}
return intval( $src );
}
echo _get_total_images( $galleries );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment