Skip Navigation

[Resolved] Record post relationship changes

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

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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 2 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#2373219

Hi team,

Do you have any suggestions how I can record changes of post relationships?

I'm building a web app that requires keeping a log of all CPTs that once belonged to another CPT even if the relationship changed in the future.

A simple table with rows that show when the relationship was created and when it was deleted would do the job.

I'm trying to figure out how I could possibly achieve this but I'm quite stuck.

Any Toolset based ideas?

Thanks!

#2373933

Hello,

There isn't such kind of built-in feature within Toolset plugins, if you delete a post relationship, it will be removed from database, and won't be recorded.

You can add a feature request for it:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Our developers will evaluate it.

#2373945

Hi Luo,

Thanks for looking into my issue.

However filing a feature request does not solve it for me at this point.

How about if we think outside the box, and actually try to achieve this using what Toolset already has to offer?

While I was waiting for your initial reply the following idea came to me as a possible solution, but yet I'll need a bit of your help here.
So In order to better understand the problem I'm trying to solve I'll try to explain in greater detail...

I'm building a web app for managing School's Library. So I have the following setup:

CPTs:
- Books
- Readers

Relationships:
- Readers-Books

CFs:
- each have a bunch of custom fields but the most important is the Barcode ID field which I use identify Books and Readers. The Barcode ID gets programatically inserted into the Book or Readers' names upon their creation, I also use these ID's to define conditionals which deliver most of the functionality(most of it goes around using these IDs).

So when a the reader wants to take a book for reading I use a post relationship form to change the Readers-Books relationship on the desired book's page and make that point to the specific Reader ID.

Once the reader wants to return the book back to the library, I use the same form to change the relationship back so the book will be related to the Libary, where Library is also a Reader - ID = 0.

My issue is that this way I can only show the current books that a specific reader is reading at the moment, and can not tell what they've read in the past.

So here comes my idea:
- What about creating a second post relationship titled "Reader-Books-Past" which will be programatically created in cases when the Reader will return the book back to the Library using the Relationship Form? We could also programatically insert values in two required custom fields - a) rent date b) return date. Rent date we will pulled from the date when the Reader-Books relationship was created initially, and the return date will be pulled from the moment when the form is submitted.

Would this be possible? Could you give me directions on programatically creating that relationship and filling in those fields if so?

Thanks in advance!

Best,
D.

#2373969

I assume we are talking about many-to-many relationship "Readers-Books".

Your idea requires two relationships, and is too complicated to maintain two relationships.

Here is a workaround you can consider:
Since the Intermediary Post Type is also a WordPress custom post type, you can use post publish date as the "created date", for example:
1) Setup many-to-many relationship "Readers-Books"
- enable options: Intermediary Post Type visible in WordPress admin menu.
- Add a custom date field "deleted-date" into the Intermediary Post Type

2) When user create new connection between "Books" and "Readers", in single "Readers-Books" post, you can use [wpv-post-date] to get the connection "created date" value.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-date

3) When user try to delete the connection, you can display a post form for editing "Readers-Books" post, after user submit the form, change the "Readers-Books" post status to "draft" and set the "deleted-date" field value as current date-time, so it won't delete post data from database.
https://toolset.com/es/course-lesson/front-end-forms-for-editing-content/

4) In the single Reader/Book post, you can display display a post view:
- Query "Readers-Books" posts
- Filter by:
a) post type relationship "Readers-Books"
b) post status is "Published" or "Draft"
- In the view's loop, display post publish date + "deleted-date" field + related Reader/Book post information
https://toolset.com/course-lesson/displaying-related-posts/

#2374005

Thanks for your quick reply Luo!

So, as far as I understand, instead of editing the relationship that was created and pointing the Book to another Reader, your idea is to create a new relationship each time the book is being moved, and change the old one from published to draft.

So this would mean that I need to change the current workflow, which currently maintains a single Book-Reader relationship that is being maintained, and is not being deleted when the Reader returns the Books to the Library(and is not being replaced by a new one when a new reader takes a book home). Instead the Book is just being related to the Library as a Reader(ID=0) when the Relationship is edited.

Also you've mentioned that in order to get the connection "created date" value, I need to have the form placed on a single Readers-Books intermediary post, however my form is located on the single Book post template. Does this mean I have to change that part of the workflow as well, and have to move the user to another page to make this action, or is there a way to pull the data from within the single Books post using shortcode attributes?

Thanks!
D.

#2374293

Nope, my idea is only one relationship: "Readers-Books", so you don't need to change your workflow.
In single Books post, you can display a post view:
- Query "Readers-Books" posts
- Filter by:
a) post type relationship "Readers-Books"
b) post status is "Publish"
- In view's loop, display the edit form link for changing "Readers-Books" post status to "Draft"
So user can change the "Readers-Books" post status in the single Books post