Skip Navigation

[Resolved] Ordering with date fields

This support ticket is created 5 years, 8 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by stephaneB-5 5 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#1260857

thkx Waqar,
it works:-) but when I sort elements by date It's not working.
I don't understand why it's doesn't work.
Can you help me ?

#1260877

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-06-06 at 09.43.08.png

Types date fields are stored as unix timestamps, which records the number of seconds since 1 Jan 1970.

With timestamps there is no "Today", there is only a specific time, e.g. midnight 5 June 2019, which has a timestamp of 1559692800. (You can try this out for yourself at unixtimestamp.com.)

So if you want to add a filter to show posts from today you need to be comparing as a number (e.g. 1559692800) not a date, and you need a between comparison, i.e. between midnight yesterday and midnight today.

The way you would add such a filter is shown in the screenshot.

#1261023

Thank you Nigel,
is it possible that every day at 23h59, the custom field'out' which is a radio is set to 1 for all those who have not validated their outing?

#1261359

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Toolset doesn't offer such functionality but you can use WordPress's cron jobs to trigger custom code that you write to update custom fields.

You set up the schedule with wp_schedule_event, and your code will need to run a get_posts query to find the posts which need updating and then update them using update_post_meta.

https://codex.wordpress.org/Function_Reference/wp_schedule_event
https://developer.wordpress.org/reference/functions/get_posts/
https://developer.wordpress.org/reference/functions/update_post_meta/

If that's not something you are able to write you can solicit help from a developer, including those listed at toolset.com/contractors/

#1261415

Thank you very much,
can you tell me what is the corresponding table to call in mysql to modify the custom type "visitor"?

Thank you very much once again

#1261837

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You shouldn't need to access the database directly using SQL, you should find WordPress functions available for everything you need to do, but if you want to study the database you'll see that the posts data is stored in wp_posts, and custom fields are stored in wp_postmeta.

See https://codex.wordpress.org/Database_Description

#1264319

Thanks Nigel, I'll go deeper into all this.

#1265083

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, let me know how you get on.

#1270489

My issue is resolved now. Thank you!