Title: (file_list) count items(images)
Last modified: September 25, 2018

---

# (file_list) count items(images)

 *  Resolved [Patrick](https://wordpress.org/support/users/zaanmedia/)
 * (@zaanmedia)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/file_list-count/)
 * Hallo guys,
 * anyone know how i’m able to count the attached images in the file_list and echo
   this number based on the post ID.
 * Searched everywere but doesn’t seem to be able to find an answer/solution to 
   my question. Can’t believe i’m the only one trying to archive this.
 * Thanks!
    -  This topic was modified 7 years, 8 months ago by [Patrick](https://wordpress.org/support/users/zaanmedia/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [7 years, 8 months ago](https://wordpress.org/support/topic/file_list-count/#post-10723124)
 * Not quite following ultimate goal, sorry. Possibly explaining your intent will
   help me work things out mentally.
 * First part says you want to get a total count of files saved. Say you have 3 
   saved for a post.
 * Second, you want to conditionally echo that count, dependent on something in 
   regards to the post ID?
 *  Thread Starter [Patrick](https://wordpress.org/support/users/zaanmedia/)
 * (@zaanmedia)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/file_list-count/#post-10723128)
 * what i try at the moment is to show the amount of images/attachments per post
   in an admin column
 * i use the file list field from cmd2 in my post type.
 * post 1 has 10 images
    post 2 has 15 images etc. etc.
    -  This reply was modified 7 years, 8 months ago by [Patrick](https://wordpress.org/support/users/zaanmedia/).
    -  This reply was modified 7 years, 8 months ago by [Patrick](https://wordpress.org/support/users/zaanmedia/).
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [7 years, 8 months ago](https://wordpress.org/support/topic/file_list-count/#post-10723231)
 * Ah. So, take the following for example.
 * I borrowed the code over at [https://github.com/CMB2/CMB2/wiki/Field-Types#file_list](https://github.com/CMB2/CMB2/wiki/Field-Types#file_list)
   as is, no edits.
 * I attached some images to a sample post, and then ran this snippet in the single.
   php file just for ease of example.
 *     ```
       var_dump( get_post_meta( get_the_ID(), 'wiki_test_file_list', true ) );
       ```
   
 * This made the following output:
 *     ```
       /app/public/wp-content/themes/twentyseventeen/single.php:23:
       array (size=3)
         25 => string 'http://www.example.com/wp-content/uploads/2018/08/1303483397485060.png' (length=63)
         26 => string 'http://www.example.com/wp-content/uploads/2018/08/1305369424349688.jpg' (length=63)
         27 => string 'http://www.example.com/wp-content/uploads/2018/08/1311363149881839.jpg' (length=63)
       ```
   
 * Based on this, you can get a count of the images by simply assigning the `get_post_meta()`
   call to a variable and using the following example code:
 *     ```
       echo count( $images );
       ```
   
 * For the example post, this would echo out “3” for my 3 images above. Should get
   you going on your needs.
 *  Thread Starter [Patrick](https://wordpress.org/support/users/zaanmedia/)
 * (@zaanmedia)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/file_list-count/#post-10723254)
 * This is simply amazing i think i have it working thanks to you!
 * So what i did is this:
 * `$images = get_post_meta( get_the_ID(), 'wiki_test_file_list', true );`
 * and then
 * `echo count( $images );`
 * Thanks again and much appreciated for all the help!
    -  This reply was modified 7 years, 8 months ago by [Patrick](https://wordpress.org/support/users/zaanmedia/).
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [7 years, 8 months ago](https://wordpress.org/support/topic/file_list-count/#post-10723268)
 * Glad that worked out for you 😀

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘(file_list) count items(images)’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [file_list](https://wordpress.org/support/topic-tag/file_list/)
 * [images](https://wordpress.org/support/topic-tag/images/)
 * [items](https://wordpress.org/support/topic-tag/items/)

 * 5 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/file_list-count/#post-10723268)
 * Status: resolved