Skip Navigation

[Resolved] Custom search between two dates

This support ticket is created 4 years, 1 month 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.

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 3 replies, has 2 voices.

Last updated by Minesh 4 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2244303

Tell us what you are trying to do?
I am trying to create an archive page where the user can choose to display all the posts that were published between two different dates
Is there any documentation that you are following?
I couldn't find any documentation regarding this topic
Is there a similar example that we can see?

What is the link to your site?

#2244839

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand, you want to add a frontend filter to your archive view where you can offer two date filters (one for start date and one for end date) to users to filter the posts by default post date. If this is correct - there is no such feature available to add frontend filters for default post date.

As a workaround, you should try to add a custom date field that should hold the publish date and then add the custom date field as a frontend filter to filter your posts between start - end date.

#2245069

Hello and thank you for your response!

Yes indeed that is excactly what I would like to achieve. The question however is, even with the workaround you propose:
1) Am I suppose to fill up the custom date field by hand every time I create a post, or is there a way for it to be automatically filled with the actuual publication date (since this already exist in WP database)?
and..
2) Even if I create this custom date field, could you please elaborate more on how to create a custom search field so that the user can access two "calendars" and change period during which he ewants to filter the posts? (the problem is that once I add a search filed based on the custom date-filed, then I cant use it again and on top of that I haven't found any way to add logic between two search-fields).

As an example, imagine that the final result at the front end should be two date calendar-like filters with which the user can set the day-after and day-before period based on wich the search for the posts will be conducted.

#2245119

Minesh
Supporter

Languages: English (English )

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

1) Am I suppose to fill up the custom date field by hand every time I create a post, or is there a way for it to be automatically filled with the actuual publication date (since this already exist in WP database)?
and..
===>
You will require to use the save_post action hook and add the code that should get the current publish date and copy it to the custom date field you created using Types.

Please note that you will have to convert the date string to Unix Timestamp as Types custom date field stores the value as Unix Timestamp.

More info:
- https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/

2) Even if I create this custom date field, could you please elaborate more on how to create a custom search field so that the user can access two "calendars" and change period during which he ewants to filter the posts? (the problem is that once I add a search filed based on the custom date-filed, then I cant use it again and on top of that I haven't found any way to add logic between two search-fields).
===>
You should add the custom date field as filter and then you should select the between, please check the following screenshot, it will give you two date picker (start and end).
- hidden link