Saltar navegación

[Resuelto] Custom post order in views

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zona horaria del colaborador: Asia/Karachi (GMT+05:00)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Waqar 2 years, 10 months ago.

Asistido por: Waqar.

Autor
Mensajes
#2628485

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!!!

#2628685

Hi,

Thank you for contacting us and I'd be happy to assist.

I'm afraid, I couldn't fully understand the requirement. The idea to set the 'random' order for the query is that it doesn't follow any specific ordering criteria.

It can't be used in conjunction with the ordering set by the other fields too.
( ref: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters )

I hope this helps and please let me know if you need further assistance.

regards,
Waqar