Navigation überspringen

[Gelöst] Front end filtering on date

This support ticket is created vor 3 Wochen, 1 Tag. 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)

Dieses Thema enthält 5 Antworten, hat 1 Stimme.

Zuletzt aktualisiert von Minesh vor 2 Wochen, 6 Tage.

Assistiert von: Minesh.

Author
Artikel
#2806220

Tell us what you are trying to do?
Hi I would like to add a filter in one of my views offering the client to filter the results between two dates.

So above my result i would like to create something like:

ONLY SHOW RESULTS BETWEEN
[Start Month v] [Start Year v] and [End Month v] [End Year v] [submit]

So select/combo boxes for the dates and years. Sorting on the publish date.

Is this possible?

#2806221

Minesh
Unterstützer

Sprachen: Englisch (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand - you want to add frontend filter for month and year and compare the selected month and year with the publish date. If this is correct:
- There is no such feature to add month or year frontend filter.

#2806223

Hmm, alright... .was already afraid...

Then I'll add an html form with a GET and URL_PARAMS, guess would make it work.

#2806226

Minesh
Unterstützer

Sprachen: Englisch (English )

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

Great - if you able to make it work, feel free to share the solution here in benefit of other users.

#2806474
2025-04-23_16-29-46.jpg

What I've done is create URL Parameters for:
Starting month
Starting Year
End Month
End Year
With a filter, after or on starting month / year and before or on end month / year.
I've added an html GET-form to the filter section of the view, with the action (url of the page) loading the same page again.
The select boxes in the form have the same name as the url parameters. This way when sumitting the form, the url parameters will be added to the url. So the page reloads with the selected/ submitted parameters.

To make sure the select boxes show the selected value, i've added some javasvript.

document.addEventListener("DOMContentLoaded", function () {
const params = new URLSearchParams(window.location.search);
const fields = ['smon', 'syr', 'emon', 'eyr', 'wpv_sort_orderby', 'wpv_sort_order'];

console.log("Select elements found on the page:");
console.log(document.querySelectorAll("select"));

fields.forEach(function(name) {
const value = params.get(name);
const select = document.getElementById(name);

if (select && value) {
console.log(`${name} → setting value: ${value}`);
Array.from(select.options).forEach(function(option) {
if (option.value === value) {
option.selected = true;
}
});
}
});
});

#2806549

Minesh
Unterstützer

Sprachen: Englisch (English )

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

Great and thank you for sharing the solution. You are welcome to mark resolve this ticket.