hi,
is it possible to disable the sorting of a view?
I have a function which orders the output of view, but if the orginal sorting active, this is not working.
thx for an answer.
alex
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Alex,
Thank you for getting in touch.
Can you let me know function that you are using to sort the view ?
Whenever you have a custom function it should overwrite the view order and use the ordering in the custom function.
Thanks,
Shane
Hey Shane,
it is an slider of cpt with rfg in it.
Here ist the code
function func_adjust_slider_posts_query( $query_args ,$view_settings, $view_id ) {
global $post;
if ( $view_id == 10897 ) {
$args = array(
'post_type' => 'veranstaltung',
'meta_query' => array(
array(
'key' => 'wpcf-highlight',
'value' => '1',
)));
$postslist = get_posts( $args );
$temp = array();
$today = date("j. F Y H:i");
$todaytimestamp = strtotime($today);
foreach($postslist as $k=>$v):
// $fieldvalues = toolset_get_related_posts( $v->ID, "termine-veranst", array( 'query_by_role' => 'parent', 'return' => 'post_object'));
$fieldvalues = toolset_get_related_posts( $v->ID, "termine-veranst", array(
'query_by_role' => 'parent',
'return' => 'post_object',
// condition to show only the next dates
'args' => [
'meta_key' => 'wpcf-datum-und-uhrzeit',
'meta_value' => $todaytimestamp,
'meta_compare' => '>',
],
// hint: order here (like in https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts) has no effect because it order just the dates not the posts
));
foreach ($fieldvalues as $fieldvalue) {
$partone = types_render_field('datum-und-uhrzeit', array('post_id' => $fieldvalue->ID,'output'=>'raw'));
/* following condition ist not necessary because meta_value in toolset_get_related_posts */
// if ($partone > $todaytimestamp) {
// $temp[$v->ID] = $partone;
// }
// ts as key => id as val
$temp[$partone] = $v->ID;
}
endforeach;
// order by keys
ksort($temp);
// $temp = array_keys($temp);
$query_args['post__in'] = (!empty($temp))?$temp:0;
$query_args['orderby'] = 'post__in';
}
return $query_args;
}
add_filter( 'wpv_filter_query', 'func_adjust_slider_posts_query', 999, 3);
thx in advance - alex
Shane
Supporter
Sprachen:
Englisch (English )
Zeitzone:
America/Jamaica (GMT-05:00)
Hi Alex,
Thank you for the code.
It would appear that you're querying the RFG and bringing that listing into the Parent however you're sorting that list based on the posts in the returned array correct?
Not sure why this isn't working, however there isn't a way to disable the sorting. However you can try using the random sort option for the view.
Thanks,
Shane