Skip Navigation

[Resolved] Link 1 CPT with another on a 1 by 1 basis and displaying the results?

This support ticket is created 5 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Anthony 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1356427

I am creating a directory site, as an example of antique dealers and events. I will have two CPT's, Dealers and Events which will have a many to many relationship. Dealers can attend many events and events can have many dealers attend.

User A (an antique dealer) will create their Dealer profile/cpt which can be viewed by end-users (C).

User B will create an event, in this case an antique fair, also viewable by end-users (C).

User A should be able to visit the event post created by user B and somehow "link" their own Dealer cpt with the event to "mark" themselves as attending the event created by user B.

User A's cpt/dealer page should then update to show them as attending that (and any other events that they have marked themselves attending) in a list.

User B's cpt/event page should also update to show user A (and any other dealers that have marked themselves) as attending in a list.
This would all need to be done on the front end.
Is this possible and if so how?
Thanks
Tony

What is the link to your site? not yet live

#1356487

Hello, yes all of this is possible in Toolset and the posts can be created and linked from the front-end of the site. The main things you'll need are a Form that creates Events, and another Form that establishes a relationship between an Event and a Dealer post (a relationship form). The lists of Events on a Dealer post, and the lists of attending Dealers on an Event post can be created with Views using post relationship filters. Those lists will be automatically updated whenever Dealers create links between their post and an event post using the relationship Form.

Generally a relationship Form contains inputs where the User will select the two posts that will be connected in the relationship. In your case, you can hide those inputs with CSS and predefine the values so your User need not select anything. The Event input value will be the Event ID, and the Dealer input value will be the logged-in User's Dealer post ID. I can show you how to add some custom markup in the Form builder in "expert mode" to hide those inputs if necessary.

Here's the documentation for relationship Forms:
https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

Let me know if I've misunderstood your project.

#1356493

Hi Christian, thank you very much, that is exactly what I was looking for. I've created a reference site at hidden link using the cooking made simple option. I've changed the relationship of recipes and videos to many-to-many. I've added a relationship form to the recipes template page but I'm not sure how to create the last part of your solution, ie auto-populating the relationship form with the relevant ID's. If you could point me in the right direction it would be very much appreciated (one thing I have noticed with the reference site is I don't seem to be able to add myself as a second user. I intended creating one to assign a video to so the form would know a specific video to use like it would a dealer cpt in my case)
Thanks
Tony

#1356673

Thank you Christian, an invite has been sent to you.

Tony

#1357271
Screen Shot 2019-10-07 at 12.23.11 PM.png
Screen Shot 2019-10-07 at 12.23.27 PM.png

Okay thanks, I was able to log in and make a few updates. I edited the Content Template for Recipes here:
hidden link

You can see that I have removed the Relationship Form block and replaced it with a shortcode block. This is necessary to predefine the parent and child items using shortcode attributes, in the current version of our Blocks system. I set the parent item successfully using the ID of the current page, like this:

[cred-relationship-form form="link-video-and-recipe-form" parent_item='[wpv-post-id id="$current_page"]' child_item='']

Again, the parent is the current Recipe post so we want to use that post's ID here in the parent_item attribute.

Next, you need to set the child item ID in the shortcode. This isn't as straightforward as the parent item, and usually requires a View. For example, let's say each User is the author of only one Video post. When they visit any Recipe post on the front-end of the site, they will have the ability to connect their one Video post with that Recipe post. So you need to know the current User's Video post ID. To do that, you must create a View of Video posts, filtered by post author, where the author is the same as the current logged-in User. The View will return only one result - the current User's Video post. Use the Loop Wizard and choose the display option "List with separators" and insert the post ID in the loop (see the two attachments here).

At this point I would place the new Video View somewhere by itself in the Recipe template, so you can test it out before integrating it in the cred-relationship-form shortcode. It should output the numeric ID of the logged-in User's Video post. If it does not do that correctly, we can troubleshoot that problem and get it working. If it does work correctly, then you can place the View shortcode inside the cred-relationship-form shortcode in the child_item attribute:

[cred-relationship-form form="link-video-and-recipe-form" parent_item='[wpv-post-id id="$current_page"]' child_item='[wpv-view name="your-video-id-view-slug"]']

Now you should see the correct parent and child items selected in the Form. Let me know if you get this far or if you get stuck, and I can take a quick look,

#1359467

My issue is resolved now. Thank you!