Skip Navigation

[Résolu] filter did not work with date field

This support ticket is created Il y a 2 années et 1 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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/Karachi (GMT+05:00)

Ce sujet contient 10 réponses, a 2 voix.

Dernière mise à jour par Waqar Il y a 2 années et 1 mois.

Assisté par: Waqar.

Auteur
Publications
#2470065

Hi,

i have two issues in a filter for a other view.

it only works the category-filter on this: lien caché

but not the date-filter below. -> its a date field

its all in there and data is good. You can see it -> Timestamps are there

And second question: How can i format the timestamps to readable dates?

thx in advance - i dont find some in Forum.

alex

#2470325

Hi Alex,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot and suggest the next steps, I'll need to see how this view and the date type field are set up in the back end.

Can you please share temporary admin login details, in reply to this message?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2471739

Thank you for sharing the access details.

I've removed the query filter and search field code for the "letzter Termin" field and added it again, with slightly different settings and it seems to be working now.
( screenshot: lien caché )

Here is the updated code for the search field, in the "Search and Pagination" section:


<div class="form-group">
	<label for="wpv-wpcf-letzter-termin_min">[wpml-string context="wpv-views"]letzter Termin von[/wpml-string]</label>
	[wpv-control-postmeta type="date" field="wpcf-letzter-termin" date_format="F j Y" default_date="NOW()" url_param="wpv-wpcf-letzter-termin_min"]
</div>
<div class="form-group">
	<label for="wpv-wpcf-letzter-termin_max">[wpml-string context="wpv-views"]letzter Termin bis[/wpml-string]</label>
	[wpv-control-postmeta type="date" field="wpcf-letzter-termin" date_format="F j Y" default_date="NOW()" url_param="wpv-wpcf-letzter-termin_max"]
</div>

#2471753
Bildschirmfoto 2022-10-07 um 08.08.15.jpg

hi thank you,

i want to show the date fields as type="select" - how can i do that with date-format? - Its only show timestamps.

And: how can i set lien caché to show only post with "letzter Termin" only in past? i do it with screenshot

thank you

best regards - alex

#2473377

Thanks for writing back.

I'm afraid, for the date type custom fields, the select type search field filter is not supported. This is why you're seeing the raw, timestamp values when you change the field type to "select".

For the past date query filter, you only needed to change the type of the filtration to the 'number' in the view "Veranstaltungs-liste-date-archiv".
( screenshot: lien caché )

#2474167
Bildschirmfoto 2022-10-11 um 15.47.22.jpg

Hi Waqar,

1. is there a jquery to reformat the timestamps to readable dates?

2. for the past date query filter - are you sure? - i did this on screenshot but it dont work - look at mine Screenshot. I also tried it with "string".

thx for an answer - best regards - alex

#2475543

1. I was able to convert the timestamp values in the search fields, using some custom script, with the help of code from this guide:
lien caché

You can see the code included and working in the view "Veranstaltungs-Liste-Filter01-archiv".


jQuery( document ).on( 'ready', function( event, data ) {
	jQuery('select[name="wpv-wpcf-letzter-termin_min"] option, select[name="wpv-wpcf-letzter-termin_max"] option').each(function () {
		var $this = jQuery(this);
		if ($this.length) {
			var selText = $this.text();
			console.log(selText);
			var conVerted = unixToDatetime(selText);
			$this.text(conVerted);
		}
	});
});

function unixToDatetime(timestamp){
	// Unixtimestamp
	var unixtimestamp = timestamp;
	// Months array
	var months_arr = ['January','February','March','April','May','June','July','August','September','October','November','December'];
	// Convert timestamp to milliseconds
	var date = new Date(unixtimestamp*1000);
	// Year
	var year = date.getFullYear();
	// Month
	var month = months_arr[date.getMonth()];
	// Day
	var day = date.getDate();
	// Hours
	var hours = date.getHours();
	// Minutes
	var minutes = "0" + date.getMinutes();
	// Seconds
	var seconds = "0" + date.getSeconds();
	// Display date time in F j Y format
	var convdataTime = month+' '+day+' '+year;
	return convdataTime;
 }

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

2. I couldn't find the page or the view that you referred to in your last message. Can you please share the link to the page where this view can be seen and the query filter is not working as expected?

#2478093

hi,

thx a lot for question 1 ! -

for question 2: this is in view 10935

thx for help, best regards - alex

ps: and sorry for delay, i was ill

#2478225

Glad I could help.

The view "Veranstaltungs-liste-date-archiv" is set to show the "Termine" repeating field group posts, which are technically separate post types from the parent "Veranstaltungen" post type.

The custom field "letzter Termin" is not part of the repeating field group "Termine", which means that they are stored with the parent "Veranstaltungen" posts and not the "Termine" repeating field group posts.

This is why the query filter for this field is not working in this view. Only the custom fields which are directly part of the repeating field group "Termine" can be used for filtering this view.

#2480167

Hi,

oh sorry - but it was in view 12454 - >

i tried it in loop object with condition:
[wpv-conditional if="( '[types field='ort' item='@termine-veranst.parent'][/types]' lte '[NOW]' )"]

or
[wpv-conditional if="( '[types field='datum-und-uhrzeit' style='text' format='d'][/types]' lte '[NOW]' )"]

but this dont work.

thx for helping - best regards - alex

Les nouveaux fils créés par Waqar et associés à celui-ci sont repris ci-dessous :

https://toolset.com/fr/forums/topic/split-conditional-display-for-the-date-field-not-working-as-expected/

#2480561

I've created a separate ticket for your question about the conditional display statement and will follow up on it shortly.
( ref: https://toolset.com/forums/topic/split-conditional-display-for-the-date-field-not-working-as-expected/ )

You're welcome to mark this ticket as resolved and start a new one for each new question or concern.