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?
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
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?
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
Wow thank you Waqar, now I learned something valuable!