Skip Navigation

[Résolu] I'm trying to make a view that only shows past events.

This support ticket is created Il y a 9 mois et 2 semaines. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 39 réponses, has 2 voix.

Last updated by Minesh Il y a 7 mois et 1 semaine.

Assisted by: Minesh.

Auteur
Publications
#2634055

The front facing of the view is: hidden link
The edit of the view is: hidden link

The view correctly shows only the past events, but say I choose May 14th 2023 which is an event date, the results don't actually match that date.

This is also true for the future view. Thank You and let me know if you need more info.

#2635775

Hi, I'm just following up on this.

#2636541

Minesh
Supporter

Languages: Anglais (English )

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

When I search for 15th May, 2023 then I can see the past event of may 14th. Is that Ok with you?

Please check the following:
- hidden link

Otherwise we will require to add another 24 hours to the event date so that it can search the event.

#2636877

Thank You, but on my end now the date field just refreshes the results and doesn't actually change them.

#2636967

Minesh
Supporter

Languages: Anglais (English )

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

Do you mean you selected the difference date and it just show the different selected date and does not refresh the view result? if this is correct then you will have to click on search button to apply the different date.

#2637207

I am clicking search. Minesh, we keep going round and round here. Are we close to a solution yet?

#2637215

Minesh
Supporter

Languages: Anglais (English )

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

Here is the video and I can see when I select the 14th may it shows two results and when I select 15th may it shows three results.
=> hidden link

Am I missing anything here?

#2637217

So it appears you've made it so that the date filter works to show only events before that date. That is not what we need. We need the view to control the past/future, but the date field to be a match for that date.

#2637579

Minesh
Supporter

Languages: Anglais (English )

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

Can you please check now, I've selected the July 15th 2023 and it shows that event only:
- hidden link

I've adjusted the code added to "Custom Code" section 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'])) {
    
    $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'])) {
    
    $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;
}
#2637633

Thank You, but this view is the past view and now it's only showing the future. The date field does work correctly now though.

#2637695

Minesh
Supporter

Languages: Anglais (English )

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

There was a typo and I've fixed that and now it will show the past events. Can you please confirm it works as expected now.

#2637807

Minesh, I think you are working on the wrong view. You did the work on hidden link based on that last link you sent.

When I requested the view to be worked on was: hidden link

Please make sure to re-read my private message with the links. We are working on one past view and one future view.

There are 3 views total.

Original(view name "community-events" id=2545): hidden link (should not have been touched)

Past (view name "community-events-past" id=4224): hidden link

Future (view name "community-events-future" id=4288): No front facing page yet. Can build one if needed.

But you are working on hidden link (view name "events" id=104) based on the last link you sent me, though the view ID in the snippet is correct. Which is a view completely separate from all the other 3 views and uses a completely different post type. This should not have been touched. You may have just sent the wrong link. Not sure.

Thank You and please let me know if you need more detail.

#2638077

Minesh
Supporter

Languages: Anglais (English )

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

The code I shared as you already noticed that its applied to your view IDs:

- Past (view name "community-events-past" id=4224): hidden link
and
- Future (view name "community-events-future" id=4288): No front facing page yet. Can build one if needed.

I just checked with the past view and when I search for 14th May 2023, it shows the correct results:

- hidden link

You can also verify for future view as well.

#2639895

Both past and future work better now. But when I select any other filter i.e. the vendor fee, the view becomes future and past again.

#2641075

I hope you are having a great day. Any updates on this?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.