Skip Navigation

[Resolved] View Block: Search by Custom Date Field, but By Year

This support ticket is created 3 years, 9 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: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by Steve Williams 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#2002535

We would like to filter (search) a View by year, using a custom field "Start date." Is there a way to do that?

We understand Toolset Views is obsolete, and we do not use Toolset Views, but we note "Building Custom Searches for Any Content Type" (https://toolset.com/documentation/legacy-features/views-plugin/front-page-filters/). We believe that's not relevant to custom search blocks in Views in Toolset Blocks. Is that right?

We have used Toolset Types to create a custom post type called "Event" with a custom field called "Start Date" (actually date and time).

We have used Toolset Blocks to create a View block with a Custom Search Filter block for Start Date. We've explored the various comparison settings.

But we're trying to search/filter by year. For example, we set "Type of Control" to "Text Input." When the visitor enters "2019," that should show events with Start Date in 2019. (Or even better, a drop-down list of years.)

I expect there's no way to do that, but I thought I'd ask.

#2002911

How do I assign a support request to a particular Toolset rep when they invite me to do so?!

In this request, Jamal suggests I assign this question to him:

https://toolset.com/forums/topic/clarify-creation-of-taxonomy-archive/

But I don't see a way to do that.

#2002935

In this other support request, Jamal wrote, "... you want to display the posts from the current month, you can add a filter on the post date."

https://toolset.com/forums/topic/clarify-creation-of-taxonomy-archive/

Does that mean there's a way to let the visitor select a month (or a year) and filter posts to that month? That's what I'm looking for!

(I'm asking about a custom field "Start Date" rather than the post date.)

#2003541

Hello Steve,

Indeed, I told you to assign the ticket to me, but I checked now and it is not possible in the Toolset support forum. That was a quick text snippet that I was using while working with the WPML support team. I confirmed that the ticket assignment is not activated on the Toolset support forum, so, I'll update my snippet. Sorry for the confusion 🙂

Toolset views plugin is now considered a legacy plugin, but we still support it for bug fixing. You can activate the legacy editor in Toolset->Settings->General(tab)->Editing Experience.

Regarding the possibility to filter by year, I am afraid, it is not an available option. But we can still achieve it using a workaround. For example, if you will be filtering by a selected number of years, you can create the dropdown using HTML, and hook it into the view's query filter with custom PHP code. You can see an example in the following reply https://toolset.com/forums/topic/create-a-filter-to-show-news-by-year/#post-362933

But, if you have multiple years, or you expect that other years will be added, I'll suggest that create an additional field to store the year. And you can add custom PHP code to sync the year from the date field. That way, you can add a filter for that field and have the dropdown generated automatically. In that case, you won't need to add custom code to change the view's query filter. You will just need one custom code to sync the year from the date field to this new field. Does it make sense?

I hope this helps. Let me know if you have any questions.

#2003571

OK, thanks for the quick answer. And thanks for the interesting link.

By the way, I believe I understand what you meant when you said "... you want to display the posts from the current month, you can add a filter on the post date." (I quoted that yesterday.) I believe you were referring to filtering the posts displayed by a view, not a custom search offered to web site visitors.