Skip Navigation

[Resolved] Custom filter by date

This support ticket is created 3 years, 7 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 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2080667
Immagine 2021-06-08 200856.jpg
Immagine 2021-06-08 200738.jpg
Immagine 2021-06-08 200314.jpg

Hi,

I've this data:

subscription number, name, lastname, user type, subscription date
1 , John, Smith, A, 01/01/2010
2 , Paul, Ross, A, 01/04/2011
3 , Kevin, Trevor, B, 14/05/2012
4 , Albert, Shane, A, 20/08/2015
5 , Walt, Bane, C, 03/10/2018
6 , Roger, Tayle, A, 21/10/2019
7 , Alfred, Htich, B, 07/11/2019
8, May, Mason, C, 08/12/2020

Each user has different step of level after some months of his date of subscription:
- after 6 months : Level 1
- after 9 months : Level 2
- after 12 months : Level 3
- after 16 months : Level 4
- after 18 months : Level 5
- after 78 months : Level 6

I need a filter to list what users are in a specific Level in a particular month and year.

Then I need 3 filters:
1. the filter for Levels (1...6) or Levels in months (6, 9, 12, 16, 18, 78)
2. the filter for Monts (1...12)
3. the filter for Years (LowerYear(subcription) ... Year(Now))

For example: Users with "Level 2" in "Aug" "2020"?

When I select all this 3 filters I can see the users list in this way:

number | name | lastname | type | subscription | level date
6 Roger Tayle A 21/10/2019 21/07/2020
7 Alfred Htich B 07/11/2019 07/08/2020

Is it possible?
How can I built filters as I need?
How can I diplay result data (users list) as I need?
I've tryed to add a filter but i don't know how to add a custom filter.
And I don't know how to manage the data in list to add a filter value : subscription date + (filter value) months

In attachment the table with the example data of users and the calculated levels/date.

Regards
Alex

#2081121

Hello,

Please elaborate the questions with more details:
How do you setup the custom post types and custom fields?
Are we talking about only one custom post type "subscription"?

#2081197
search-result-example.jpg
search-example.jpg
Immagine 2021-06-09 091117.jpg
Immagine 2021-06-09 091026.jpg
Immagine 2021-06-09 090959.jpg
Immagine 2021-06-09 090939.jpg
Immagine 2021-06-09 090922.jpg
Immagine 2021-06-09 090823.jpg

Hi,

"How do you setup the custom post types and custom fields?"
I've a Custom Post Type called "Utenti" (users)
with this Custom Fields.
- Numero Iscrizione ("subscription number" : Number)
- Cognome ("lastname" : Text)
- Nome ("name" : Text)
- Tipo Anagrafica ("user type": Select/Text)
- Data Iscrizione Ordine ("subscription date" : Date)
(in attachment)

"Are we talking about only one custom post type "subscription"?"
Yes ("Utenti" or "Users in this case)

In attachement my custom type, the custom fields configuration and an example of the result i need.

The "Level date" is not a real custom field but it is a "calculated field" (on the fly) in the list, its value is the "subscription date" + the "months' level" searched.
For example:
Subscription date : November 14 2019
To became a Level 3 after : 12 months
The user became Level 3 in: November 14 2020

If I search users in LEVEL 3 (+12 Months) at November 2020 I find the users subscripted in November 2019
or
If I search users in LEVEL 4 (+16 Months) at November 2020 I find the users subscripted in July 2019
or
If I search users in LEVEL 6 (+78 Months) at June 2021 I find the users subscripted in December 2014
or
If I search users in LEVEL 6 (+78 Months) at December 2026 I find the users subscripted in June 2020
and so on...

#2081321

Thanks for the details, there isn't such kind of built-in feature within Toolset plugins, it needs custom codes, for example, after user submit the search form, you can use filter hook wpv_filter_query to trigger a PHP function:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

In this PHP function get the search inputs "Month" and "Year" value, and turn it into time stamp value:
hidden link

Then apply the value into query as filter on custom field "subscription date":
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters