Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I add the values of meta fields in the loop?

Say each post has a custom field called "rating" (or whatever) and its got a value of 1 to 5 and its kept in a custom post meta.

In the loops when Im going through all the post, how would I add up all the post metas together to get a total "rating" value?

share|improve this question
1  
Is this really your question, if you can get the values of the post meta in a loop, cannt you just add those ?? –  Maruti Mohanty Dec 18 '13 at 18:36
    
@JonFury as I suggested in this comment on another of your questions, please conduct research through other channels before posing the question on WPSE. This question, too, would have been quickly answered by both Google and the WordPress codex. I strongly recommend that you read the codex entry on Writing a Plugin and that you spend some time browsing the Function Reference. –  boscho Jan 1 at 22:43

1 Answer 1

You can put the meta value of each post within an array while inside loop. Then just calculate the average of the ratings after the loop ends. for getting meta values you can see this link Function Reference/get post meta

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.