Skip Navigation

[Resolved] Calculate the time between two posts published times

This support ticket is created 5 years, 5 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 10 replies, has 3 voices.

Last updated by DavidH606 5 years, 5 months ago.

Assisted by: Beda.

Author
Posts
#1130574
time diff output.JPG
time diff views.JPG

Tell us what you are trying to do? Create a simple sign / sign out app

Is there any documentation that you are following? Have been following previous support topics

Is there a similar example that we can see? hidden link

What is the link to your site? hidden link

I've created two post types, sign in and sign out.
I want to output the post creation times for these in Unix time, then try to subtract the time in from the time out to get the time difference, i.e in at 16:15 out at 16:30 duration 15 minutes.

recognising I need to get the two values into the one view I've tried two methods,
1) call the data from the correct posts using $id.
2) call the data using two views to call it and one to combine it.

The first methods looks great but it's not catching the right data (check in and out times are the same)
The second method looks likes it's not going to allow me to sequence the data for the calculation.

Question, Am I headed the right way, and which of the two methods should I use to get the data ready for the calculation ?

Also let me know if you want to log in, I'll build us a staging site to play with.
(but hopefully screenshots below will let you see what I'm trying)

Many thanks for your support, more than happy to share this module when it's built.

D

#1131086

the item/post_id/id attribute is broken and does not accept $post_slug
Only $current_page and a specific post ID will work
I escalated this to the Developers so they can fix it.

#1131087

Brilliant Thanks Beda ?

#1132141

Hi David,

The issue that Beda informed you about in his previous reply already is in our queue.

But I just need to understand your request clearly and discuss it with you possibly, we can find a better solution.
I'm not sure how you constructed your website but let me mention some information that would help you:

The $id attribute should be used to retrieve data from a post in three ways:
Check our documentation here: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-title
1- id= '$parent' : this is to get the needed information from a parent post
2- id= 'post-id': such that, post-id is the real ID of the post that you need to catch information from, example: id="20"
3- id= '$custom post name': this is to get information from a related post with post name equals to 'custom post name'

I see that you need to record the sign in and sign out times and calculated the difference and shot it in a page.
So, there should be something that connects the sign in and the sign out times.

One of the ways you can do that, is to connect the sign in and the sign out post types by a one-to-one relationship.
Can you please check these two documentation pages to understand how this can be done?
Post Relationships: https://toolset.com/documentation/post-relationships/
How to set-up post relationships using Toolset: https://toolset.com/documentation/post-relationships/how-to-set-up-post-relationships-using-toolset/

I can suggest many ways for you to do that. but please take a look at the previously mentioned documentation pages and then kindly let me know if this helped you.

Thanks.

#1132144

Changing ticket status.

#1132576
Timing App Diagram.jpg

Thanks, I'm wary of implementing relationships as I'm worried about the affect it will have on the existing developments.

The Staff Member (custom user) Signs In (custom post) to a Service User (custom post) and then signs out. I want to see the in/out & duration times in both the Service User View and the Staff View which is a custom layout calling loads of views based on User ID. I also want a view that pulls in all staff and their total times, the Timesheet View

Is that a Many to Many Relationship?

Please See Diagram Attached for the Service User and Staff Views, the 'Timesheet View' is not shown, it's just a list of users and their TOTAL Hours.

Really appreciate the help!

Thanks, D

#1133402

I've hit some issues with the relationships migration, I'll open a separate ticket for that. Can we keep this one open in the meantiime please?

#1133431

I wanted to confirm here that I obviously was partially wrong

Here is the correct statement about how that works (related to post id):
There are legacy and new relationships, and on legacy, you would still just pass $post-type-slug to get the parent of the post in the loop
With the new M2M relations and new syntax, you also need to tell what part of the relation to get.

So, the modern usage of id/item/post_id in a Toolset ShortCode is:
- a numeric ID of existing post
- $parent (parent set by WP Hierarchy)
- $current_page (the page or post where the View is inserted to, hence, container ID)
- $post-type-slug.{role} where "{role}" should be the role of the post Type we want to call (can be "child", "parent" or omitted on legacy relations).
==> It calls the parent/child of a post in the loop as set by Types.
Note that in legacy, as said, .{role} is NOT passed and hence, will ALWAYS call the parent as set by types of that post type passed (for example id="$parent-post-type-slug" for legacy, and id="$parent-post-type-slug.parent" for modern relationships)

That, in regard to what I believed to be a BUG.
We will update the doc in regard.

Please revisit this in light of the new information and let me know if the issue still persists.

#1133526

So if I understand you correctly, if I stick with legacy I'll need to think carefully about how I connect these post types as parents / children

but with relationships I'm a bit more free as I can define relationships just with id="$parent-post-type-slug.parent where $parent-post-type-slug is not a 'parent' other than in this query?

#1134094

The relationships must logically exist in both cases.
Just calling $parent-post-type-slug is not enough, there must be such a related post type.

For example, you have 2 Post Types in a relationship and on Post Type A you want to call related Post Type B data.
Those posts must first be connected, otherwise, there is not anything to "return" when called.

So those check-in and check-out posts should be somehow connected to a common child post, from where you can then call that data and display or calculate with it.

#1137540

I've backed away from full integration for now, I'll get relationships working and then re-visit this plan.

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