Skip Navigation

[Resolved] How to create a search view showing posts relevant for a certain date?

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

Problem:

How to create a custom search with a datepicker which will filter between to date values of custom fields?

Solution:

- Create a view in Classic mode:
https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/
- On the Search and Pagination section (If you do not see that section click the Screen Option at the top to enable it)
- Click the New Filter to add a new filter.
- Use the information below:

1. Opening Date for the field
2. Set the data type to UNASSIGNED (because the dates are stored as UNIX timestamp in Toolset)
3. Set the comparison to "Lower than or Equal to".
4. In the Field options section take note of the URL Param as you will use it later.

- Click the New Filter to add this time the closing date with the information below:

1. Closing Date for the field
2. Set the data type to UNASSIGNED (because the dates are stored as UNIX timestamp in Toolset)
3. Set the comparison to "Greater than".
4. In the Field options add the value of the URL param you noted in the previous step.
5. The same URL param for opening and closing date will cause both datepickers take the same value when the customer adds the date.

- In the HTML code of the Closing date is automatically created add a style or CSS code to hide the closing date as the viewer only needs one datepicker and the closing one will automatically get the value of the opening one in the search. So maybe a style="display: none;" will do.

- In the same Search and Pagination section add a submit button using the editor buttons to have a way to submit the date.
- Save the view and use it on a page.

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.

This topic contains 5 replies, has 2 voices.

Last updated by valterB 1 year, 7 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2618677

How to create a search view showing posts relevant for a certain date?
I am trying to create search view that filters posts according to a date range (from opening day to closing day).
It should be possible to put in a certain date, with the list showing only the posts with relevant opening/closing dates.
Can you give me guidance on how to do this? Thanks in advance!

#2618709

Christopher Amirian
Supporter

Languages: English (English )

Screenshot 2023-06-25 at 13.35.55.png

Hi there,

I assume that you have custom fields for the opening date and closing date.

To achieve the result you want you need to follow the steps below to create a custom search and add proper date pickers in the search field:

https://toolset.com/course-lesson/creating-a-custom-search/

For the date custom fields you need to set the field settings on the right sidebar to do comparison with "Unassigned" mode.

Please check the screenshot.

Thanks

#2619013

Thanks for quick response!

I am trying to make the search show which mountain huts that are open at specific dates.

I have these date format fields:
1. Date for visit (to be used for user input in search form)
2. Opening date for the huts
3. Closing date for the huts

When the user puts a date in field #1 the Search results should show all huts that are open that day.
I suppose I must connect these fields in some way, but I can not understand how.

Thanks in advance for any advice!

#2619085

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Let me check to understand if I get it right:

Opening date for the huts, is a custom field that you already pre-filled in the backend and now has a certain date. You do not want to show this field in the custom search.

Closing date for the huts, is a custom field that you already pre-filled in the backend and now has a certain date. You do not want to show this field in the custom search.

Date for visit is a custom field that you added but it doe snot have a value assigned to it in the backend and you want to use it in the custom search for the user to add to filter in the front end.

If I am wrong please clarify.

Also, I'd appreciate it if you could give me the URL/User/Pass of your WordPress dashboard after you make sure that you have a backup of your website.
It is absolutely important that you give us a guarantee that you have a backup so if something happens you will have a point of restore.

Make sure you set the next reply as private.

It will help to see it in action. Please give me the View and the URL to see it in the front end.

#2619281

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Please check this video to see how I managed to do that:

hidden link

Steps:

- Create a view in Classic mode:
https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/
- On the Search and Pagination section (If you do not see that section click the Screen Option at the top to enable it)
- Click the New Filter to add a new filter.
- Use the information below:

1. Opening Date for the field
2. Set the data type to UNASSIGNED (because the dates are stored as UNIX timestamp in Toolset)
3. Set the comparison to "Lower than or Equal to".
4. In the Field options section take note of the URL Param as you will use it later.

- Click the New Filter to add this time the closing date with the information below:

1. Closing Date for the field
2. Set the data type to UNASSIGNED (because the dates are stored as UNIX timestamp in Toolset)
3. Set the comparison to "Greater than".
4. In the Field options add the value of the URL param you noted in the previous step.
5. The same URL param for opening and closing date will cause both datepickers take the same value when the customer adds the date.

- In the HTML code of the Closing date is automatically created add a style or CSS code to hide the closing date as the viewer only needs one datepicker and the closing one will automatically get the value of the opening one in the search. So maybe a style="display: none;" will do.

- In the same Search and Pagination section add a submit button using the editor buttons to have a way to submit the date.
- Save the view nd use it on a page.

That should do it.

#2619317

My issue is resolved now. Thank you!