Skip Navigation

[Resolved] Searching a date field by year only

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by ianG-5 3 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#2012025

I have a custom field "Field type - Date" with "Input only the date".
In a view I would like to query filter using this field but only search by year (YYYY).

I have tried the Query Filter as "number that is in the following..." I have also tried date and string and I have tried in and like but I cannot find as solution that returns a result unless I input using a datepicker.

#2012281

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ian,

Thank you for getting in touch.

Will this be a frontend filter or is it a backend filter? Assuming that this will be a frontend filter then it won't be possible to do. This is because the date field is queried as a timestamp which contains all the relevant information of that date such as month, day, year and time.

It is not possible with the view filters to filter by the custom field using the year only.

Thanks,
Shane

#2012711

Hi Shane, I worried that might be the case.
Presumably this would be possible with wpv_filter_query though? Or am I going to have to do full shortcode?

I need to get a list of all posts, get all years, display all years as links, when a year is clicked filter posts by that year.

with the filter query, as it uses the timestamp I cannot think of a way that you can pass it a url, or could I pass it IDs?

#2012905

Or will I need to create another field/fields that store at text or number rather than the unix timestamp?

#2014119

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ian,

The simplest solution here would be to create a single line field that would just hold the year only.

This will allow to create a filter for the post by year only.

Thanks,
Shane

#2017883

Thanks Shane,
The Solution I went for was to create a new taxonomy and use custom code to update the taxonomy when a date is selected.
From all I have ready, taxonomy searching should be a lot quicker than a custom field especially if I proceeded down the original path it would have been multiple chained custom field searches.

#2017885

My issue is resolved now. Thank you!