Skip Navigation

[Resolved] Filter with "year" textfield by current year

This support ticket is created 5 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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by katjaL 5 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1243415

I have a custom textfield where there is year (as a string). I'm trying to create a filter that shows only current year's results.
I can't make it work with any combination string/number/SIGNED/UNSIGNED - equal/like/in - THIS_YEAR

Or did I miss something? How would you suggest me to achieve this result?

#1243546

Hi Katja,

Thank you for waiting.

I noticed that the custom field "Vuosi" is set to save numeric year value in the single line type field and is not a "Date" type field. This is the reason why the default date filtering options are not working with it.
( the date field stores value in UNIX timestamp format )

To make this filtering by year work, please follow these steps:

1. You'll need a custom shortcode which can return the current year. Here is a link with an example code snippet, and it can be added into the active theme's "functions.php" file:
hidden link

2. Next, please add this shortcode's name "year" ( or whatever name you've set in your code) in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
( screenshot: hidden link )

3. In the "Query Filter" section of the view, you'll add a filter to show posts where the "Vuosi" field's value is equal to the value passed as the shortcode attribute "year".
( screenshot: hidden link )

On your page where you'd like to show this view, you can pass this shortcode attribute like this:


[wpv-view name="kotimaiset-elokuvateatteriensi-illat-elokuvat-etusivu" year="[year]"]

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1243550

Hi Waqar and thank you very much, again 🙂 I will try what you suggest with the year field.

But would you please bear with me awhile and inform me if normal datefield could be used here. I tried multiple ways (with the other field I mentioned, which is a true date field) to filter THIS_YEAR, but I couldn't get the result list. And if that's the case, I don't quite understand the meaning of THIS_YEAR. In what situations can it be used?

#1243900

Hi Katja,

Thanks for writing back.

In case of the date type field like "Ensi-ilta", you can set the query filter to bring in the posts having value "between" "THIS_YEAR" & "FUTURE_YEAR".
( screenshot: hidden link )

You'll find more details on the topic of date field comparisons and timestamp values in this guide:
https://toolset.com/documentation/user-guides/date-filters/

regards,
Waqar

#1243923

Wow thank you Waqar, now I learned something valuable!