Title: Finding and adding custom fields together
Last modified: August 19, 2016

---

# Finding and adding custom fields together

 *  [enkayes](https://wordpress.org/support/users/enkayes/)
 * (@enkayes)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/finding-and-adding-custom-fields-together/)
 * Hello all,
 * I’m very new to WordPress, so I hope this isn’t terribly easy and I’m just being
   foolish, but I can’t figure it out.
 * I’d like to add a custom field in each post with a number, then have a loop on
   the front page that goes through all the posts and gets all those fields and 
   adds them.
 * Example:
 * /*Run Through Posts*/
    Post #1: apples = 1 Post #2: apple = 3 Post #3: apples
   = 0 Post #4: apples = -2 /* Front Page*/ Total Apples: 2
 * I’m assuming this is possible, but can someone point me in the right direction?
 * I’ll continue to work on this and update the forum if I come up with a solution.
 * Thanks!
 * –Nick

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

 *  [gerbilk](https://wordpress.org/support/users/gerbilk/)
 * (@gerbilk)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/finding-and-adding-custom-fields-together/#post-1470054)
 * you need to add something inside your loop like $applestotal + $apples where 
   $apples is your custom field value, this will add to $applestotal every time 
   the loop runs through
 *  [ambrosite](https://wordpress.org/support/users/ambrosite/)
 * (@ambrosite)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/finding-and-adding-custom-fields-together/#post-1470058)
 * Not tested, but something like this should work:
 *     ```
       <?php
       $total = 0;
       while (have_posts()) : the_post();
           $postmeta = get_post_custom($post->ID);
           echo "Apples = {$postmeta['apples'][0]}";
           $total += (int) $postmeta['apples'][0];
       endwhile;
       echo "Total Apples: $total";
       ?>
       ```
   
 *  Thread Starter [enkayes](https://wordpress.org/support/users/enkayes/)
 * (@enkayes)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/finding-and-adding-custom-fields-together/#post-1470083)
 * +5 internets to you both! Thank you!
 *  [ambrosite](https://wordpress.org/support/users/ambrosite/)
 * (@ambrosite)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/finding-and-adding-custom-fields-together/#post-1470112)
 * If you implement this on a live site, please give us the link. I’d be interested
   to see it.

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

The topic ‘Finding and adding custom fields together’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [ambrosite](https://wordpress.org/support/users/ambrosite/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/finding-and-adding-custom-fields-together/#post-1470112)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
