Skip Navigation

[Résolu] filter button "past" and "future"

This support ticket is created Il y a 1 an et 2 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.

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

Last updated by alexd-6 Il y a 1 an et 2 mois.

Assisted by: Minesh.

Auteur
Publications
#2559235

Hi,

i have and posttype termine which has an date field with time.

And i have a view as custom search, which should have a button for "past" and "future" for show post only "older" or "newer" posts from TODAY()

I dont find anything in Support-Forum about.

is this possible?

thx for an answer,

best regards - Alex

#2559893

Minesh
Supporter

Languages: Anglais (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand - you added two buttons to your view one that should display the old events and one button that should display the future events. - is that correct? If yes:
- What view you are using - Are you using classic or block view?
- how exactly you have added those buttons?

If you can share admin access details and problem URL where you added your view I can review your current setup and that will help me to guide you in the right direction.

*** 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.

#2560005

Minesh
Supporter

Languages: Anglais (English )

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

So what if you create a two views - one view that should display posts in future and one view that should display old (past) posts and you should also create two pages and link the URL of those pages to the buttons.

Does that makes sense?

#2560027

hi minesh,

can we do this not with a filter?

And: can we sort about the date in field "eventdate"?

thx - alex

#2560081

Minesh
Supporter

Languages: Anglais (English )

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

I share you the straight forward way as with the filter it might require custom code.

And: can we sort about the date in field "eventdate"?
==>
Do you mean you want to compare the old (past) and future posts with the custom everntdate field and also want to order by everntdate custom field?

#2560095

Hi,

yes that would be great.

#2560111

Minesh
Supporter

Languages: Anglais (English )

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

Sorry I do not get what you want exactly yet.

Can you please share brief information about with that way you want to go and do you have custom date field that holds the startdate?

#2560133

Hey - at all:

its just look like a simple event (cpt termine) listing orderd by "eventdate". Filter should be "future" -> all post from today, "past" -> all posts from today in past. "search" to search all events text.

i did it in view 2824
hidden link

you know what i mean?

best regards - alex

#2560145

Minesh
Supporter

Languages: Anglais (English )

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

What I'm asking is - you want to compare the custom field "eventdate" or default post publish date to compare the future and past post?

#2560149

i want eventdate to compare both, future and past

thx - alex

#2560155

Minesh
Supporter

Languages: Anglais (English )

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

Can you please check now: hidden link

I've added the Past and Future links at top of the page within your search and pagination section of your view:
- hidden link

<div class="form-group"> <a href="?past=1"> Past </a> | <a href="?future=1"> Future </a> </div>

Then with the "Custom Code" section offered by Toolset, I've added the code snippet "toolset-custom-code" and added the following filter code to it:
=> hidden link

add_filter('wpv_filter_query', 'func_show_past_future_posts', 99, 3);
function func_show_past_future_posts($query, $setting, $view_id) {
  global $wpdb;
  if($setting['view_id'] == 2824) {
    if(isset($_GET['past']) and $_GET['past'] == 1 ) {
      
       $query['meta_query'][] = array(
                                  'key' => 'wpcf-eventdate',
                                  'value' => time(),
                                  'type' => 'UNSIGNED',
                                  'compare' => '<'
       							);
           
    } else if(isset($_GET['future']) and $_GET['future'] == 1 ) {
       $query['meta_query'][] = array(
                                  'key' => 'wpcf-eventdate',
                                  'value' => time(),
                                  'type' => 'UNSIGNED',
                                  'compare' => '>'
       							);
    }
    
      
    
  }
  return $query;
}

Can you please confirm it works as expected now.

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

#2560739

Hi Minesh - thx a lot this is working like a charm! - Why isnt it available in filters for the view? i think this where a nice feature.

One question about sorting in this view that you edited:

i sort it on field "eventdate" - asc - can i use in case "past" desc and in case "future" sort asc? - That would be great.

thx and best regards

alex

#2560747

Minesh
Supporter

Languages: Anglais (English )

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

Can you please check now: hidden link

I've adjusted the code as given under with the "Custom Code" section offered by Toolset:
=> hidden link

add_filter('wpv_filter_query', 'func_show_past_future_posts', 999, 3);
function func_show_past_future_posts($query, $setting, $view_id) {
  global $wpdb;
  if($setting['view_id'] == 2824) {
    if(isset($_GET['past']) and $_GET['past'] == 1 ) {
      
       $query['meta_query'][] = array(
                                  'key' => 'wpcf-eventdate',
                                  'value' => time(),
                                  'type' => 'numeric',
                                  'compare' => '<'
       							);
      
      	$query['orderby'] = array( 'meta_value_num' => 'DESC');
    	$query['meta_key'] = 'wpcf-eventdate'; //
    	
      
      
           
    } else if(isset($_GET['future']) and $_GET['future'] == 1 ) {
       $query['meta_query'][] = array(
                                  'key' => 'wpcf-eventdate',
                                  'value' => time(),
                                  'type' => 'numeric',
                                  'compare' => '>'
       							);
      
      	$query['orderby'] = array( 'meta_value_num' => 'ASC');
    	$query['meta_key'] = 'wpcf-eventdate'; //
    	
      
    }
    
      
    
  }
  return $query;
}

I hope everything is resolved now and feel free to open a new ticket with every new question you may have. You can mark resolve this ticket.

#2560751

Hi Minesh - thx a lot it works perfect! - best regards, warmly - alex

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