Title: Summing numeric Meta-Value(s)
Last modified: July 27, 2018

---

# Summing numeric Meta-Value(s)

 *  Resolved [Maximus](https://wordpress.org/support/users/abayomi222/)
 * (@abayomi222)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/summing-numeric-meta-values/)
 * I created custom meta with cmb2 plugin as well as custom columns.
 * Below is my code for the column display with content of the custom meta created.
 * function columns() {
 * $columns = array(
    ‘_my_creative_column’ => array( ‘label’ => _(‘Create’, ‘cbi-
   tt’), ‘type’=> ‘post_meta’, ‘meta_key’=> ‘shaping’, ‘orderby’=> ‘meta_value’,‘
   sortable’=> true, ‘def’=> ”, ),
 *  ‘_my_design_column’ => array(
    ‘label’ => _(‘Design’, ‘cbi-tt’), ‘type’=> ‘post_meta’,‘
   meta_key’=> ‘inspiring’, ‘orderby’=> ‘meta_value’, ‘sortable’=> true, ‘def’=>”,),
 *  ‘_my_members_column’ => array(
    ‘label’ => _(‘Members’, ‘cbi-tt’), ‘type’=> ‘
   post_meta’, ‘meta_key’=> ‘allmembers’, ‘orderby’=> ‘meta_value’, ‘sortable’=>
   true, ‘def’=> ”, ),
 *  ‘_my_quorum_column’ => array(
    ‘label’ => _(‘Quorum’, ‘cbi-tt’), ‘type’=> ‘post_meta’,‘
   meta_key’=> ‘meeting’, ‘orderby’=> ‘meta_value’, ‘sortable’=> true, ‘def’=> ”,),
 * $columns = apply_filters ( ‘cbi_tt_columns_bigworker’, $columns );
    foreach (
   $columns as $key => $col) { $this->cols->add_column ( $key, $col ); } }
 * With the code above, i successfully created four columns to the existing columns
   for my custom post type post lists in the admin section.The columns were populated
   with meta_value(s) from their respective meta_key(s).
    Now, i have been trying
   to create a single column (called Members Quorum – which is an addition of the
   last two columns above) instead of two. The value will be the sum of the meta_value(
   s) for both meta_key(s).
 * How do i go about this? Can someone please help?
 * Also, how do i also do the sum based on user roles and permission. In other words,
   some values will not be summed, if user does not belong to a certain role.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Maximus](https://wordpress.org/support/users/abayomi222/)
 * (@abayomi222)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/summing-numeric-meta-values/#post-10533392)
 * This is what the new column will be :
    ‘_my_membersquorum_column’ => array( ‘
   label’ => _(‘Members Quorum’, ‘cbi-tt’), ‘type’=> ‘post_meta’, ‘meta_key’=> ‘’,//*****************‘
   orderby’=> ‘meta_value’,//************** ‘sortable’=> true, ‘def’=> ”, ),
 * Like i said earlier, the content will be the sum of Meta-values from two Meta-
   Keys => allmembers and meeting
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [7 years, 10 months ago](https://wordpress.org/support/topic/summing-numeric-meta-values/#post-10533706)
 * Not quite sure how this is related to CMB2 at all, truth be told.
 * That said, you’ll need to set up a way to grab all the intended columns for a
   given row, and perform the necessary math calculations so you can output the 
   final total.
 * You can conditionally perform math calculations using the `current_user_can` 
   capabilities function.
 * We’re probably not going to be too much help beyond that, in this case though.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Summing numeric Meta-Value(s)’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/summing-numeric-meta-values/#post-10533706)
 * Status: resolved