Here is my query args :
$query_args = array(
'post_type' => 'rented_properties',
'post_status' => 'publish',
'order' => 'DESC',
// 'fields' => 'SUM(amount_to_paid)',
);
$my_querys = null;
$my_querys = new WP_Query($query_args);
My meta key is amount_to_paid
, and I want to get the sum all the meta_values of this query condition. Please suggest your answer with query_args
.
My Scenario : I have 1000 posts and each with meta_key amount_to_paid and it has some value. Now I filter 20 posts and want to get sum of meta_value of amount_to_paid . Did you got me now?
amount_to_paid
is added/changed, WP_Query retrieves posts, and that's all it does. It won't do calculations for you and it isn't SQL, you need to do those parts using the information WP_Query returns. Think of it asWP_Post_Query
rather thanWP_SQL_Query
amount_to_paid
and it has some value. Now I filter 20 posts and want to get sum of meta_value ofamount_to_paid
. Did you got me now?WP_Query
won't calculate that for you, you need to grab the posts, then do the adding in an additional step, there's no argument you can add toWP_Query
to get an answer from it