Summing numeric Meta-Value(s)
-
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.
- The topic ‘Summing numeric Meta-Value(s)’ is closed to new replies.