Skip Navigation

[Assigned] Custom code to make the The Calendar plugin compatible

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 replies, has 1 voice.

Last updated by Rafael Corts 18 minutes ago.

Assisted by: Minesh.

Author
Posts
#2854669

I need custom code to make the The Calendar plugin compatible. Some time ago, you created code for me to solve a compatibility issue between Toolset and The Calendar. Now I have a new issue: I would like to change the order of the list in the different Views based on the “Esdeveniment” field.

I would like to know whether it is possible to modify the code so that, in each View, I can choose a different sort order: in one View from the nearest date to the farthest, and in another View the reverse order.

Below is the code you created for me. Could you modify it so that, in each View, I can change the order of the listing using a custom field called “Esdeveniments”.

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

function func_remove_unwanted_posts( $query_args ,$view_settings, $view_id ) {
    global $post;
    global $current_user; 
    if ( $view_id == 3003 ) {
       
      $query_args['suppress_filters'] = 1;
       
      
          
    }
    return $query_args;
}
add_filter( 'wpv_filter_query', 'func_remove_unwanted_posts', 999, 3);


add_action('pre_get_posts', 'func_tribe_events_date_filter_adjust',99,1);
function func_tribe_events_date_filter_adjust( $query ) {
	  global $WP_Views;
  
  
               $target_view_ids = array(5575,3003,5429);    
  
              if(in_array($WP_Views->current_view,$target_view_ids)){
     
      		 /// if($WP_Views->current_view == 5575){
                
                	 $meta_query = $query->get('meta_query') ?: [];
                
                	
                	$remove_keys = ['tec_event_start_date', 'tec_event_end_date'];

                    // Remove unwanted keys
                    foreach ($remove_keys as $key) {
                        if ( isset($meta_query[$key]) ) {
                            unset($meta_query[$key]);
                        }
                    }
                	 $query->set('meta_query', $meta_query);
                	
                
                
              }
  		return $query;
}
add_filter( 'wpv_filter_query_post_process', 'func_sort_event_date_within_view_result', 10, 3 );
function func_sort_event_date_within_view_result( $query, $view_settings, $view_id ) {
  
    $target_view_ids = array(5575,3003,5429);    
    
    if (in_array($view_id,$target_view_ids) && !empty($query->posts)) {

        usort($query->posts, function($a, $b) {

            $date_a = get_post_meta($a->ID, 'wpcf-data-esdeveniment', true);
            $date_b = get_post_meta($b->ID, 'wpcf-data-esdeveniment', true);

            $time_a = strtotime($date_a) ?: 0;
            $time_b = strtotime($date_b) ?: 0;

            return $time_b - $time_a; // DESC
        });

        $query->found_posts = count($query->posts);
        $query->post_count = count($query->posts);
    }

    return $query;
}

#2854732

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I need to check how the view is configured and can you please tell me with that view you want to display posts in DESC order and with what view you want to display posts in ASC.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.