Title: Count Items in Loop
Last modified: August 20, 2016

---

# Count Items in Loop

 *  Resolved [itsonlybarney](https://wordpress.org/support/users/itsonlybarney/)
 * (@itsonlybarney)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/)
 * I have created a Custom Post Type, and modified the archives loop to output just
   the link to the Custom Post.
 * Is it possible to count the number of items extracted from the database using
   the loop?
 * This is my loop query:
    `$loop = new WP_Query( array( 'post_type' => 'cclub','
   orderby' => 'title', 'order' => 'ASC' ) );`
 * I thought I could count the items using the count() function from PHP using the
   follow:
    `$count = count($loop);`
 * But alas the answer given was 1.

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/#post-2680230)
 * Why not just set up a simple variable and increment it at the start of each loop
   pass?
 *  Thread Starter [itsonlybarney](https://wordpress.org/support/users/itsonlybarney/)
 * (@itsonlybarney)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/#post-2680232)
 * If I wanted to have two columns, and the items listed in alphabetical order, 
   I want the columns to be like:
 *  A | E
    B | F C | G D | H
 * rather than:
 *  A | B
    C | D E | F G | H
 * This is assuming my understanding of what you are saying is correct.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/#post-2680235)
 * So when $count <5, display the posts in the left column.
    When $c > 4 && $c <
   11, display posts in the left column. When $c > 10, $c = 1
 *  Thread Starter [itsonlybarney](https://wordpress.org/support/users/itsonlybarney/)
 * (@itsonlybarney)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/#post-2680237)
 * When I ran the following code:
    `$count = count($loop);`
 * $count was always equal to 1, no matter how many items the loop pulled out of
   the DB.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/#post-2680239)
 * try:
 * `$count = $loop->post_count;`
 *  Thread Starter [itsonlybarney](https://wordpress.org/support/users/itsonlybarney/)
 * (@itsonlybarney)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/#post-2680244)
 * Thanks alchymyth, your code worked perfectly

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

The topic ‘Count Items in Loop’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [itsonlybarney](https://wordpress.org/support/users/itsonlybarney/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/count-items-in-loop-2/#post-2680244)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
