Counting the number of images in a post
-
Hi
What I am trying to do can be best described by looking at this previous thread.
Whilst I have worked through that method and included the PHP, I am getting random numbers coming out that seem to have no reference to the post they are referring to. There seems to be no logic to what number are spat out!
This is the code I have in place below – is there something I should be calling to get the post ID?
<?php $id=the_ID(); $total_attachments = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' && ID=$id"); echo $total_attachments; ?>
Thanks,
Ian
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Counting the number of images in a post’ is closed to new replies.