wpdb – add up values for custom field within a specific category

I have a custom field called “points.” This is a numerical value, so some posts have 2 points, some have 10, etc.

I want to count the total number of “points” for all of the posts within a given category who also have the custom field “cf_Category” with the value of “Chapter Building”

So, maybe query all the posts in Category X, whose value for meta key “cf_Category” is “Chapter Building” and then add up the values for the meta key “Points” and then echo that number.

Does that make sense? I’m able to add up all of the points for all posts, but am having trouble limiting it to one category.

Thanks in advance!

Source: wpdb

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.