WordPress meta fields to posts and add them?

What we have: multiple entries of post type with arbitrary field meta_key. How to use standard query WP_Query to get all posts meta_key and add them?
June 10th 19 at 15:29
2 answers
June 10th 19 at 15:31
// parameters for the query, WP_Query
 $args = array(
 'post_type' => 'post'

 $query = new WP_Query( $args );
 $posts = $query->posts;

 $summ = 0;

 foreach ($posts as $post) {

 $summ += get_post_meta($post->ID, 'meta_key', true);



 echo $summ;
June 10th 19 at 15:33
Thank you! Just perfect!

Find more questions by tags WordPress