Skip Navigation

[Résolu] sort timestamp about month

This support ticket is created Il y a 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

This topic contains 3 réponses, has 2 voix.

Last updated by Waqar Il y a 2 mois.

Assisted by: Waqar.

Auteur
Publications
#2684929

Hi,

here helped me nigel of you team me perfect with:

https://toolset.com/forums/topic/filter-date-only-about-days-not-each-hour-timestamp/

All works fine!

An Answer about this - is it possible to set the Dates also to the month? That means - i will show here only one month in Dropdown if there more that one event in the month..

hidden link

thx in advance - best regards - alex

#2685181

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Alex,

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

The date/time custom field stores the values in a UNIX timestamp format. To filter the results based on month and most likely by the year too, you can add two select type custom fields:

1. Month:
( Options: January, February, March, .... )

2. Year:
( Options: 2024, 2023, 2022, .... )

This way, you'll be able to include the search field filters in your views and archives, based on month and year too.

regards,
Waqar

#2685219

hi Waqar,

thank you for this, but i have a filter for a date field with filter like:

[wpv-control-postmeta field="wpcf-letzter-termin" type="date" date_format="F j, Y" url_param="wpv-wpcf-letzter-termin" default_label="bitte Datum auswählen" type="select"]

i can do the format="Y" - but this dont work. Did you read the thread from Nigel and me? -> https://toolset.com/forums/topic/filter-date-only-about-days-not-each-hour-timestamp/

if you want, you can get access from me 😉 - best regards - alex

#2685562

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back and yes, I have read the other thread, between you and Nigel.

Let me give you a brief overview so that it is clear what has been discussed so far and why I suggested having separate custom field for each month (and optionally for a year).

The Toolset's date/time type field stores the values in a UNIX timestamp format.
( ref: hidden link )

When time is enabled, it stores the exact time-based value for the selected date and when only the date is enabled, it stores the value of the selected date at midnight (12 am).

The code that Nigel provided in the other thread, helped to covert already stored date values at different times to this default midnight time, on the same dates. But we still don't have the information about the month stored separately anywhere.

> i can do the format="Y" - but this dont work.

- When we use format="Y", it shows the label or text value in the month format for the dropdown, but the actual comparison or filtering is still performed based on the stored UNIX timestamp values in the fields. which is why it doesn't work because those values represent a particular day and not a month.

That is why, you'll need an additional custom field to store the month's information if you'd like to filter by that.

And you don't necessarily need two separate fields for the month and the year. You can store them both in a single field, in a format like:

- Feb-24
- Jan-24
- Dec-23
- Nov-23
- Oct-23
...........

Depending on how these posts are being added and edited on the website, custom code can be used to programmatically update the value in this new custom field automatically, whenever a date is saved/updated, in the original date type field.

And for the posts where the date type field's value is already saved, custom code like the one Nigel shared earlier, can be used to automatically update the values in this new field too.

I hope this explanation helps and let me know if you have any follow-up questions.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.