Title: Add and Average Custom Fields
Last modified: August 21, 2016

---

# Add and Average Custom Fields

 *  [slicesofamerica](https://wordpress.org/support/users/slicesofamerica/)
 * (@slicesofamerica)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/add-and-average-custom-fields/)
 * I’m creating a music review website. For each album, there are 7 criteria, each
   set up as its own custom field. How can I add these and divide by 7 to get the
   average? I would also like to display the average. Don’t know where to begin!
   I am currently doing the math by hand.
 * [http://taylorlasseigne.com/albums/atlas/](http://taylorlasseigne.com/albums/atlas/)

Viewing 1 replies (of 1 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/add-and-average-custom-fields/#post-5122428)
 * If these are held in custom fields, they are most likely stord in the `wp_postmeta`
   table and are related to the post ID. You’ll need to know the name of each one,
   and you’ll be able to do this. As a pure example without knowing what the fields
   are called…
 * This is a slightly innefficient way of doing it, but it pretty much explains 
   what you’ll need to add into your code.
 *     ```
       $criteria_1 = get_post_meta ($post->ID, 'criteria_1', true);
       $criteria_2 = get_post_meta ($post->ID, 'criteria_2', true);
       $criteria_3 = get_post_meta ($post->ID, 'criteria_3', true);
       $criteria_4 = get_post_meta ($post->ID, 'criteria_4', true);
       $criteria_5 = get_post_meta ($post->ID, 'criteria_5', true);
       $criteria_6 = get_post_meta ($post->ID, 'criteria_6', true);
       $criteria_7 = get_post_meta ($post->ID, 'criteria_7', true);
   
       $average = ceil ($criteria_1 + $criteria_2 + $criteria_3 + $criteria_4 + $criteria_5 + $criteria_6 + $criteria_7) / 7;
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Add and Average Custom Fields’ is closed to new replies.

## Tags

 * [average](https://wordpress.org/support/topic-tag/average/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/add-and-average-custom-fields/#post-5122428)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
