Skip Navigation

[Resolved] Create a date filter for a repeated number field

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Minesh 1 month, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2762976

My site is a repository of philosophy articles.

I want to add a filter which will allow users to filter query results by a custom field called 'publication date' in the search view and in archives. The custom field is a number field. I want the filter to allow the user to enter a date range - ideally in two fields, 'from' and 'to' - and if an article has a publication date within that range, it will come up in the query. For example, an article written in 2013 should come up when the user enters 2000 in the 'from' field and 2020 in the 'to' field. How do I do that?

There is a twist!
Some articles have more than one date. It's because they have different editions or have been republished. On the back end, I simply 'Allow multiple instances of this field'. I would like the filter to find the entry on any of the publication dates. For example, an article written in 1987 that was reprinted in 2013 should come up when the user enters 2000 - 2020, but also when they enter 1950 - 2000. Is this possible?

There is an even worse twist!
Some texts are collections that have been written over a longer period of time. For those, I enter date ranges in the 'publication year' field, for example: 2005-2015. It would be amazing if the filter could find such a text if the search query hits any of the years in the range, e.g. if the user searches for 2000 - 2010, or 2010 - 2020, or even 2007 - 2008. Is this possible?

I am using the original text editor, not the blocks one.

#2763164

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

First of all, I would like to know what plugins you are using and I need to review the content structure you have currently.

Can you please send me details about with what post type you added the date custom field and send me admin access details and let me review your current structure and once I review it, I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2765950

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

When I try to login using the admin access details you shared I got the following error:

Error: The password you entered for the username testadmin is incorrect.

Can you please send me working admin access details.

As well as tell me where you created the repeated number field with what post type.

I have set the next reply to private which means only you and I have access to it.

#2769967

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now:
- hidden link

I've added the following custom search filter to your view's "Search and Pagination" section just before the search button:

 <div class="form-group">
	<label for="wpv-wpcf-year_min">[wpml-string context="wpv-views"]Publication Year From[/wpml-string]</label>
	[wpv-control-postmeta type="textfield" field="wpcf-year" placeholder="Year From" url_param="wpv-wpcf-year_min"]
</div>
<div class="form-group">
	<label for="wpv-wpcf-year_max">[wpml-string context="wpv-views"]Publication Year To[/wpml-string]</label>
	[wpv-control-postmeta type="textfield" field="wpcf-year" placeholder="Year To" url_param="wpv-wpcf-year_max"]
</div>

You can adjust the styling as required later on.

It offers "Publication year From" and "Publication year To" textbox where you can add the year range and perform the search. I hope the above solution will help you to resolve the issue.

#2777667

Hi Minesh,
Thank you for your help, this seems to work well with both single dates and repeat field. Is there a chance this could still work with the date ranges? As in, the 'even worse twist' from my first post? At the moment, I can't even enter a range in the date field because it only allows numbers...

#2777671

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

No - there is no such feature available that you can add date range in date-picker.

#2777699

Thanks for clarifying. Would it be possible in some other way, e.g. if I set this up not as a number field but a text field? Or perhaps a taxonomy? Any ideas and suggestions welcome.

#2777700

Also, is there some way to only display the first of the values from the multiple-instance field? That is, I want it to be found when people look for any of the publication dates, but I only want to display one of them on the front end.

#2777801

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thanks for clarifying. Would it be possible in some other way, e.g. if I set this up not as a number field but a text field? Or perhaps a taxonomy? Any ideas and suggestions welcome.
====>
I already seen that you added textfield as from and to to find year range.

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery for the original issue reported.

May I kindly ask you to open a new ticket with every new question you may have in future. For now, I'll split the ticket with your addon question and I'll followup on that with the following split ticket:
- https://toolset.com/forums/topic/split-create-a-date-filter-for-a-repeated-number-field-show-first-instance-of-repeating-field-group/