Display number of images actually posted

I'm currently using this PHP code to pull the number of images from a post.

$attachments = get_children(array('post_parent'=>$post_array[0]['ID']));
$image_count = count($attachments);

It is currently pulling any image that is "attached" to the post, however I would like for it to pull the actual number of images that were used in the post. How would I display the number of images actually displayed in the post?

Answers 1

  • Something like:

    $image_count = substr_count( $post_array[0]['post_content'], '<img');
    

    It won't cover images in galleries ... but you can count IDs in gallery shortcode.


Related Questions