Skip Navigation

[Gelöst] I'm trying to make a view that only shows past events.

This support ticket is created vor 1 Jahr, 4 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 39 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Minesh vor 1 Jahr, 2 Monaten.

Assistiert von: Minesh.

Author
Artikel
#2642977
#2643123

Minesh
Supporter

Sprachen: Englisch (English )

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

What we are doing is as you requested we are only displaying the past events with the view that you created to display the past event by default when page loaded first time.

Now what happens is, when you select the date as 14th may and select vendor fees filter to yes, it will display posts where date equal to 14th and vendor fees equal to yes.

I see it working here:
- versteckter Link

How you want to apply the multiple filters?

#2643487

Now use any filter and not the date filter and the view reverts back to past and future as I mentioned in my previous reply.

#2643491

Minesh
Supporter

Sprachen: Englisch (English )

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

I know now what you mean.

I see now when I remove the filter it does show the correct past event:
- versteckter Link

I've adjusted the code added to "Custom Code" section as given under for both future and past event views:

add_filter( 'wpv_filter_query', 'func_filer_show_past_events', 99, 3 );
function func_filer_show_past_events( $query_args, $view_settings, $view_id ) {
 
  if( $view_id == 4224 and !isset($_GET['wpv_view_count'])) {
    
    $args = array(
      'relation' => 'AND',
      array(
        'key' => 'wpcf-date-ce',
        'value' => strtotime('23:59:59'),
        'compare' => "<",
        'type' => 'numeric'
      ),
      
    );
    // add these arguments to your meta query
    $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : [];
    $query_args['meta_query'][] = $args;
  }else{
    
    if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and 
       is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { 
      
      	
      
      	$meta = $query_args['meta_query'];
        foreach($meta as $k=>$v):
            if($v['key'] == 'wpcf-date-ce'){
                  
                    $filter_array = array(
                        'relation' => 'AND',
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce'],
                          'compare' => ">=",
                          'type' => 'numeric'
                        ),
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce']+86400-1,
                          'compare' => "<=",
                          'type' => 'numeric'
                        ));
     
              
                $query_args['meta_query'][] =  $filter_array;
                unset($query_args['meta_query'][$k]);                    
                break;
            }
        endforeach;
      }else{
      		$args = array(
      'relation' => 'AND',
      array(
        'key' => 'wpcf-date-ce',
        'value' => strtotime('23:59:59'),
        'compare' => "<",
        'type' => 'numeric'
      ),
      
    );
    // add these arguments to your meta query
    $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : [];
    $query_args['meta_query'][] = $args;
      
      }
    	
  }
  
  
  return $query_args;
}

add_filter( 'wpv_filter_query', 'func_filer_show_future_events', 99, 3 );
function func_filer_show_future_events( $query_args, $view_settings, $view_id ) {
 
  if( $view_id == 4288 and !isset($_GET['wpv_view_count'])) {
    
    $args = array(
      'relation' => 'AND',
      array(
        'key' => 'wpcf-date-ce',
        'value' => strtotime('23:59:59'),
        'compare' => ">",
        'type' => 'numeric'
      )
    );
    // add these arguments to your meta query
    $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : [];
    $query_args['meta_query'][] = $args;
  } else{
    
    if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and 
       is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { 
      
      	$meta = $query_args['meta_query'];
        foreach($meta as $k=>$v):
            if($v['key'] == 'wpcf-date-ce'){
                  
                    $filter_array = array(
                        'relation' => 'AND',
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce'],
                          'compare' => ">=",
                          'type' => 'numeric'
                        ),
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce']+86400-1,
                          'compare' => "<=",
                          'type' => 'numeric'
                        ));
     
              
                $query_args['meta_query'][] =  $filter_array;
                unset($query_args['meta_query'][$k]);                    
                break;
            }
        endforeach;
      
     }else{
      
      $args = array(
      'relation' => 'AND',
      array(
        'key' => 'wpcf-date-ce',
        'value' => strtotime('23:59:59'),
        'compare' => ">",
        'type' => 'numeric'
      )
    );
    // add these arguments to your meta query
    $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : [];
    $query_args['meta_query'][] = $args;

     }
    	
  }
  return $query_args;
}
#2646327

Thank You, but now the views display no results at all. Even with no filters being used.

#2646359

Minesh
Supporter

Sprachen: Englisch (English )

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

You asked for the past view to display only past events on the following page:
- versteckter Link

When I remove the filter - I can see there is no past event, as you can see now as I removed the filter, as you can see it shows all future events:
- versteckter Link

That is why its not displaying any post as there is no past event available. (currently I removed the filter so you can see all events those are belongs to future not past).

Let me know once you review that and I'll apply the past event filter again.

#2646361

No, there are plenty of past events. Now even the default original that should show all(past and future) is blank as well: versteckter Link

The past view now only shows future: versteckter Link

If you look at the backend of the Community Events CPT: versteckter Link

You can see past and future events. Like this past one: versteckter Link

#2646363

Minesh
Supporter

Sprachen: Englisch (English )

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

Can you please check now: versteckter Link

I've adjusted the code for both past and future events as given under:

add_filter( 'wpv_filter_query', 'func_filer_show_past_events', 99, 3 );
function func_filer_show_past_events( $query_args, $view_settings, $view_id ) {
 
  if( $view_id == 4224 and (!isset($_GET['wpv_view_count']) or
      (isset($_GET['wpv-wpcf-date-ce']) and empty($_GET['wpv-wpcf-date-ce']))) ) {
      
    $args = array(
      'relation' => 'AND',
      array(
        'key' => 'wpcf-date-ce',
        'value' => strtotime('23:59:59'),
        'compare' => "<",
        'type' => 'numeric'
      ),
      
    );
    
    // add these arguments to your meta query
    $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : [];
    $query_args['meta_query'][] = $args;
    
  }else if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and 
       is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { 
     
      	$meta = $query_args['meta_query'];
        foreach($meta as $k=>$v):
            if($v['key'] == 'wpcf-date-ce'){
                  
                    $filter_array = array(
                        'relation' => 'AND',
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce'],
                          'compare' => ">=",
                          'type' => 'numeric'
                        ),
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce']+86400-1,
                          'compare' => "<=",
                          'type' => 'numeric'
                        ));
     
              
                $query_args['meta_query'][] =  $filter_array;
                unset($query_args['meta_query'][$k]);                    
                break;
            }
        endforeach;
      }
      

  return $query_args;
}

add_filter( 'wpv_filter_query', 'func_filer_show_future_events', 99, 3 );
function func_filer_show_future_events( $query_args, $view_settings, $view_id ) {
 
  if( $view_id == 4288 and (!isset($_GET['wpv_view_count']) or
      (isset($_GET['wpv-wpcf-date-ce']) and empty($_GET['wpv-wpcf-date-ce']))) ){
    
    $args = array(
      'relation' => 'AND',
      array(
        'key' => 'wpcf-date-ce',
        'value' => strtotime('23:59:59'),
        'compare' => ">",
        'type' => 'numeric'
      )
    );
    // add these arguments to your meta query
    $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : [];
    $query_args['meta_query'][] = $args;
    
  } else if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and 
       is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { 
      
      	$meta = $query_args['meta_query'];
        foreach($meta as $k=>$v):
            if($v['key'] == 'wpcf-date-ce'){
                  
                    $filter_array = array(
                        'relation' => 'AND',
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce'],
                          'compare' => ">=",
                          'type' => 'numeric'
                        ),
                        array(
                          'key' => 'wpcf-date-ce',
                          'value' => $_GET['wpv-wpcf-date-ce']+86400-1,
                          'compare' => "<=",
                          'type' => 'numeric'
                        ));
                
                $query_args['meta_query'][] =  $filter_array;
                unset($query_args['meta_query'][$k]);                    
                break;
            }
        endforeach;
      
     }
    	
  return $query_args;
}

I've checked on load it shows correct past event, then when I select date filter it dhows correct selected date event and when I remove the date filter it again shows the correct past event and when I select the fees filter it shows the correct event.

#2646371

I think that did it. Thank You. I'm going to push it to the live site tomorrow and I'll let you know how it goes.

#2646381

Minesh
Supporter

Sprachen: Englisch (English )

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

Glad to know that now all issues are address with the past and future event views. You're welcome to mark resolve this ticket when you can.

#2649459

Apologies. I thought I already closed this. Everything is working great on the production site. Thank You for all your help and I hope you have a great week!