hello,
I am trying to achieve a custom post order in a view, using multiple custom fields to define the order of the results.
I wrote a function which seems to work fine, apart from the last requirement, which is to use the 'random' ability in addition to the custom ordering that I require. My code is the following:
function tssupp_modify_orderby( $view_args, $view_settings, $view_id ){
if ( 1293 == $view_id ) { // Edit ID
$view_args['meta_query'] = array(
// 'relation' => 'OR',
'entrylabel' => array(
'key' => 'wpcf-entry-label',
),
'isverified' => array(
'key' => 'wpcf-is-verified',
),
'isnew' => array(
'key' => 'wpcf-is-new',
),
'random' => array(
'key' => 'wpcf-old-id',
),
);
$view_args['orderby'] = array(
'entrylabel' => 'DESC',
'isverified' => 'DESC',
'isnew' => 'DESC',
'random' => 'RAND',
);
unset($view_args['wpv_orderby']);
unset($view_args['wpv_order']);
}
return $view_args;
}
add_filter( 'wpv_filter_query', 'tssupp_modify_orderby', 101, 3);
Could you help with the 'random' pls?
Thank you!!!