Skip Navigation

[Resolved] Query Filter by month using URL parameter

This support ticket is created 7 years, 4 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 7 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#471540

Dear Sir/Madam,

I have an event custom post with start and end date, I want to have a dropdown select from Jan to Dec to filter the event where the start or end date is in the selected month, how can I make the filter using url parameter?

Best regards,

Kelvin.

#471718

Dear Kelvin.

I assume we are talking about filter by post published date, it is possible, please check our document:
https://toolset.com/documentation/user-guides/filtering-views-query-by-date/
You can also set the values to come from external parameters, using the two classical ways to pass information into a View: a shortcode attribute or an URL parameter.

#472045

Dear Luo Yang,

Sorry I am not using the publish date for the filter, I create the custom post with custom date field.

Best regards,

Kelvin

#472495

Custom date field is also a custom field, so you can follow our document to make the filter using url parameter:
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
section "Source for compare value":
URL parameter
The value for the filter is set in the URL to the page
This will let you create custom searches filters for Views, where visitors can control what the View will show.

But in the parameter search form of Views plugin, the custom date field displays as a datepicker, there isn't such an option to display it as select dropdown menu, you will need to try with custom codes to add the filters, for example:
Views filter hook "wpv_filter_query"
https://toolset.com/documentation/user-guides/views-filters/#wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.

Hope it help

#472844

Dear Luo,

Sorry I have no idea how the wpv_filter_query be applied in the View filter, could you show some example to archive my requirement?

Best regards,

Kelvin

#473218

There is a misunderstand, in Views parameter filter form, the custom date field is display as a datepicker, there isn't such an option to display as a dropdown menu, if you need the dropdown menu, you will need try with custom PHP codes:
1) Create a dropdown menu to pass URL parameter to the view,
2) turn the URL parameter into time stamp value, for example PHP function strtotime()
hidden link
3) Then add filters to your view with the filter hook "wpv_filter_query"

There are lots of examples of using the filter hook "wpv_filter_query", in out document, there is an example:
https://toolset.com/documentation/user-guides/views-filters/#wpv_filter_query
And
hidden link

Hope it help

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