Skip Navigation

[Resolved] Creating custom filter by month

This support ticket is created 5 years, 9 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.

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)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1256807

Tell us what you are trying to do?
Create a custom filter by month from a date field in custom post type.

Is there any documentation that you are following?
No, I can't find anything that is specific to my use case.

Is there a similar example that we can see?
I've laid out the buttons I would like to filter by here - hidden link
with the addition, the filter dates can't be shown if they are in the past.

What is the link to your site?
hidden link

#1257771

Hello,

There isn't such a built-in feature within Views search form, it needs custom codes.

The custom date field created with Types plugin stores timestamp value, you can use Views filter hook to apply your own custom filter to Views query, for example:

1) When user choose option "Jan", pass URL parameter "my-month=1" to view,
2) Use Views filter hook "wpv_filter_query" to trigger a PHP function
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
3) In this PHP function, do these:
- get URL parameter "my-month" value,
- get the timestamp values(2019-01-01 :00:00:00 and 2019-02-01 :00:00:00) of the specific month by URL parameter "my-month"
- apply them into Views' query
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
meta_compare (string) - Operator to test the 'meta_value'. ... 'BETWEEN',

For your reference.

#1262169
Screen Shot 2019-06-07 at 8.14.14 pm.png
Screen Shot 2019-06-07 at 8.14.32 pm.png

Currently it looks like this. (See attached images)

I am not sure where to add the custom code you have advised. Can you please provide more detail? With my current code, all workshops are displayed even when it isn't the correct month.

Thank you.

#1263661

According to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/
You can contact one of Toolset certified consultants for it.

You can put your custom PHP codes into your theme file "functions.php", and in the document I mentioned above:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
There is an example for using filter hook "wpv_filter_query"

For your reference.