Is it possible to get SUM for total value of INTEGER values over many POSTS with WP_Query?

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


\- 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
14/4= 3.5

3.5 is the only value I want returned from my function.



This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer