Modify sorting of meta column value
Hey guys,
i wonder if it’s possible to change the sorting behaviour of columns whose column values are modified (for display).
i use this code to change the values:
// sum up MEP voting columns
add_filter( 'cac/column/meta/value', function ( $value, $object_id, $column ) {
$cf_keys = array('up_votings', 'down_votings');
if ( 'column-meta' == $column->get_type() AND in_array($column->get_field(), $cf_keys) ) {
$value = array_reduce(explode(',', $value), function($item, $carry) {
$carry += intval($item);
return $carry;
}, '');
}
return $value;
}, 10, 3 );
basically, I sum up the values that come from a serialized array (i.e. a:3:{i:16861;i:1;i:16859;i:1;i:16892;i:1;}
) but this obviously troubles the sorting mechanics.
i already tried different field types like ‘numeric’, ‘multiple values’ and ‘count’ but all of them obviously can’t deal with it.
do we need to add a custom column type for this then?
You must be logged in to reply to this topic.