OK, I know not to directly query the database, but I need a total sum of all posts that have parent id X and I really don’t want to pull all the posts out and then loop over them to get the value I need. I just want to say something like
WP\_Query
\- return SUM of custom field rating value / TOTAL NUMBER OF POSTS
. where parent id = 1
Is this possible at all?
In the db I have
\- post id: 1. ratingValue: 5
\- post id: 2. ratingValue: 6
\- post id: 3. ratingValue: 1
\- post id: 4. ratingValue: 2
SUM would be 5+6+1+2=14
TOTAL NUMBER OF POSTS=4
14/4= 3.5
3.5 is the only value I want returned from my function.
TIA
[ad_2]