Skip Navigation

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

This support ticket is created hace 1 año, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Luo Yang hace 1 año, 5 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#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: enlace oculto

1) Create a custom code snippet "default-day-filter":
enlace oculto
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:
enlace oculto
It works fine.

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