Skip Navigation

[Resolved] Set search filter date picker default as text instead of a date

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: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 1 year, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#2613587

Hi There,

When setting up a view filter of a date field I wish to use the date picker but as default values I want to display texts "dates from" and "dates to" instead of a date as currently when the view is initially loaded it displays all the posts instead of filtering by the default dates. This is fine except the search from still shows the default dates but obviously the results don't match. Can this be done?

Any help would be appreciated.

Thanks in advance.

#2613771

Hello,

I assume you are using legacy editor to setup the post view.

In the custom search form, you can find and edit the date field search control shortcode, and setup the attribute "default_date", for example:
[wpv-control-postmeta field="wpcf-test-date" url_param="wpv-wpcf-test-date_max" default_date="FUTURE_DAY(3)"]

More helps:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-control-postmeta
attribute "default_date"
https://toolset.com/documentation/legacy-features/views-plugin/date-filters/

#2615421

Yes I'm using legacy.

I understand the function of the default_date but it doesn't actually apply the selected dates to the view when the page initially loads which I thought is what would happen. I was just wondering if text could be used as a placeholder instead whilst still using the date picker function?

#2615687

No, there isn't such kind of built-in feature within Toolset plugins, it needs custom codes, see below sandbox website:
Login URL: hidden link

1) Create a custom code snippet "default-day-filter":
hidden link
with below codes:

add_filter('wpv_filter_query', function($query, $settings, $view_id){
  if($view_id == 69 && !isset($_GET['wpv-wpcf-test-date_min'])){
    	$_GET['wpv-wpcf-test-date_min'] = strtotime('+1 day');
  }
	return $query;	
}, 1, 3);

Please replace 69 with your post view's ID, replace "test-date" with your custom date field slug

2) Test it in frontend:
hidden link
It works fine.

More helps:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
hidden link