Skip Navigation

[Resolved] Timestamp in URL for direct link

This thread is resolved. Here is a description of the problem and solution.

Problem:
display only 30 days posts of future date using views

Solution:
You can use view's hook "wpv_filter_query" to filter the posts when the view loaded first time. It will also allow you to filter the view.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/timestamp-in-url-for-direct-link/#post-1077424

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 6 years, 3 months ago. 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 7 replies, has 2 voices.

Last updated by FrancoisJ6057 6 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1075142
View  Filtre CPT   Formation Mauricie (1).png

Hi,

My custom search is working good, but I was wondering if is it possible to share a link so people only sees courses starting between today and 30 days from now?

I explained : people can choose two dates in the search section, to see which courses between date A and B. When tey do so, the dates are shown in URL using Unix timestamp (ex.: ?debut_max=1535068800). For other "static" values, I can use the text value to share the URL (ex. : ?wpv-location=Online). Is there a way to add a special parameter in URL to "dynamically" show courses beginning in 30 days or less from today?

I could create another view with a predetermined window of 30 days from today, but users cannot reset the values (or choose their own dates) to see all the courses... I would like to have only one view.

thanks

#1076075

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - do you mean that when view is loaded first time - it should display all courses that is within 30 days limit from current date?

#1076287

Hi Minesh,

Yes, that's it. Actually, I want to put a custom link in my menu so people can see which courses are starting in the next 30 days. And, if the want to change the search parameters (ex. : only see online courses, or starting in the next 60 days), then they can change the filtering options.

#1076304

Minesh
Supporter

Languages: English (English )

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

Well - so we need to compare the course start date field and it should be less than 30 days when view loaded first time - correct? If Yes, Could you please tell me the name of your custom date field and share access details with me.

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#1077424

Minesh
Supporter

Languages: English (English )

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

Could you please check now: hidden link

I've used view's hook wpv_filter_query to filter the posts when the view loaded first time. It will also allow you to filter the view.

I've added following code to your current theme's functions.php file:

add_filter('wpv_filter_query', 'wpv_show_prefilter_data', 99, 3);
function wpv_show_prefilter_data ( $query_args, $view_settings, $view_id ) {
   
     if( $view_id == 20 && !isset($_GET['wpv_view_count']) ) {
          
		  $start_date = time();
          $end_date = strtotime('+30 days', $start_date);
         
		 $query_args['meta_query'][] = array(array(
            'key' => 'wpcf-date-de-debut',
            'value' => array($start_date, $end_date),
            'compare' => 'BETWEEN',
            'type' => 'NUMERIC,'
         ));
          
          
    }
    return $query_args;
}

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#1077458

Hi,

I see what you have done, but it's not what I had in mind if I can say. The thing is that with this method, if people go to the search page, the only sees the courses starting in 30 days or less, but they don't know it.

I want people that goes to the search page to see all courses. But, I want to put a link in my menu (or a button) so that people that goes to the search page see a "pre-filtered" search of courses starting soon. Given that the url parameters allows to do something like that, that's what I was looking for (ex. : ?start_from=XYZ&start_to=ZYX). For example, if I put a link with the location in the url parameter, it will only shows the courses corresponding to that location.

So, maybe it's not possible to have that kind of behavior (to have a "?start_from=TODAY&start_to=TODAY(30)") kind of thing and should make a different view, on a different page, with that filter...

#1077464

Minesh
Supporter

Languages: English (English )

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

Yes - its better you should create a new page and create a separate view that shows future 30 courses and add this view to this page and add a link to the page you created.

#1077609

Thanks