Skip Navigation

[Closed] Simple dropdown filter by year

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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 4 replies, has 2 voices.

Last updated by Luo Yang 9 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#254594

I am trying to:
Create a simple dropdown sidebar filter that will list the years of my custom post so the viewer can select a year and have only the publications for that year be displayed.

I've tried to create a parametric search that will populate the dropdown with year from the publication-date using the following:

[wpv-control taxonomy="focus" url_param="wpv-focus" type="select" hide_empty="true" format="Y" default_label="Select a Dimension"]

and then in my layout, here is my loop:

<wpv-loop>
[types field="publication-date" style="text" format="Y"][/types]
</wpv-loop>

But this gives me a blank dropdown. If I use type="date", i get the calendar, but no way to just select a year.

There's got to be a simple way to do this and I just can't wrap my brain around it right now. Any suggestions?

#254802

I assume the "publication-date" field is a custom date field created with Types, it is not possible within Views filter form, the format attribute of shortcode wpv-control do not support year "Y" as value, see our document:
https://toolset.com/documentation/views-shortcodes/#wpv-control

format:
'%%COUNT%% %%NAME%%'
optional - %%COUNT% will display the number of post for the taxonomy term and %%NAME%, the taxonomy term. e.g. format=’%%NAME%% (%%COUNT%%)’

I suggest you create a custom field "year" to store the year value of each post, then setup the dropdown in the filter form as what you need.

#254912

I'd like to avoid creating another field for year. Is there a simple javascript I can add to extract the year from the date and use that as a variable in the filter? Or use a range - for example, find all records in 2004 by suing between 1/1/2004 - 12/31/2004. Either way, I can manually add the dropdown list since it won't contain many years, I just need a way to compare against the publication date and only select the records for that year.

#254922

That was a typo - I meant to say "by using between 1/1/2004 - 12/31/2004." Not suing anyone!

#255062

Sorry, there isn't such simple javascript, you can try Check out our certified partners for it:
https://toolset.com/consultant/

Or I you can try manually create the "year" dropdown, and use views filter hook wpv_filter_query to apply the timestamp range into query:
wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

The topic ‘[Closed] Simple dropdown filter by year’ is closed to new replies.