Created
March 4, 2012 08:56
-
-
Save banago/1971523 to your computer and use it in GitHub Desktop.
Calculates average of values taken from custom fields out of a WordPress loop. Built of Jason ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function: Average | |
* Calculates average of values taken from custom fields out of a WordPress loop. Built of Jason ;) | |
* Author: Baki Goxhaj | |
*/ | |
function average( $post_no ); | |
$no = 0; | |
$query = new WP_Query('posts_per_page=' . $post_no ); while( $query->have_posts() ) : $query->the_posts(); | |
// Adding | |
$no = $no + get_post_meta( $post->ID, 'cutom_field_name', true ); | |
endwhile; | |
//Calculate Average | |
$average = $no / $post_no; | |
echo $average | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment