• Resolved Maximus

    (@abayomi222)


    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

    (@abayomi222)

    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

    (@tw2113)

    The BenchPresser

    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.