Skip Navigation

[Résolu] disable sorting for view

This support ticket is created Il y a 3 années et 4 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Shane Il y a 3 années et 4 mois.

Assisté par: Shane.

Auteur
Publications
#2113425
Bildschirmfoto 2021-07-13 um 16.46.59.jpg

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

#2113577

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: 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

#2113593

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

#2114385

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: 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