Skip Navigation

[Resolved] Form to Create One Post Type + Select Another (many to many)

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 12 replies, has 2 voices.

Last updated by Minesh 2 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2747526

Scenario:
Post type - Member
Post type - Group
Currently set up in a many-to-many relationship. A member can belong to many groups. A group can have any number of members.

I have a form so that a user can create their Member post type. But I'd also like them to select from all the available Groups. This seemed a lot more straightforward when it was just a parent/child relationship.
Am I missing the option within the post form creation?

I'd also like to attach a year to a member's time within a group. So like: Bob Smith --> Fun Group during the 2023 year. Should that be a taxonomy or custom field on one (or both) of the post types? Because then they could belong to a totally different group in 2024 (or even many).

I'm fine doing this with separate forms if necessary. One to create the Member and then another to establish the relationship with the Group (and the year).

#2747871

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I'm not sure if you are aware that you can add the post-relationship custom fields when you have many to many post relationship. It is called intermediary post fields.
- https://toolset.com/course-lesson/many-to-many-post-relationships/

Please check the following related ticket:
- https://toolset.com/forums/topic/adding-a-custom-field-to-an-intermediary-port/#post-1929013

#2748843

Those resources don't address how to add these items to a cred form.

In a typical parent--child relationship, there are options (or at least there used to be) to set the related post type in a form. How can I go about doing that for the scenario I've described above?

And do I need a relationship form to set the intermediary post field separately? Or can I do it using the same form as the one that sets the Member--Group relationship?

#2749144

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

If you have many-to-many post relationship with intermediary post type where you added the custom field, in that case, For interacting with intermediary post type custom field, you will have to use the post relationship form.
- https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/

If you have actual use case - please share details where you want to add relationship form and what field you want to edit and what is your expected result.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2751649

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share details on what page/post you added the form "Member Intake" - also once the new member (user) created using this form to what group you want to connect - what is the post relationship you want to use?

Is there any post-relationship custom field (intermediary post custom field) with your many-to-many?

If you can share bit more details and step by step information about what you want to achieve and where the things located that will help me to guide you in the right direction.

I have set the next reply to private which means only you and I have access to it.

#2753677

hidden link

I'd like it to be a many to many relationship.
A member can belong to multiple groups, as well as belonging to them at different points in time. That's why I'd like the "Years" field used to establish what year the member was a part of that particular group.
So someone could be:
Bob Smith --> Fun Group (2023)
Bob Smith --> Boring Group (2024)

But all the rest of Bob Smith's information would be the same. They could just periodically add an additional relationship down the line (though I'd still like them to establish one on this initial form).

#2755049

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see the member form with the link you shared:
- hidden link

Using above form you will create a single new member post.

To connect the post in many to many post relationship, you will have to create another form using post relationship form:
- https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/

When you create post-relationship form it will allow you to select the year field that is the intermediary post type field.

So I've created the following relatioinship form for your post relationship between members and entities:
- hidden link

As you can see the field Years for Entities is available.

Now, question is where you want to add the relationship form on what page or post?

- Do you want to allow user to connect new post in many to many or only edit the relationship?
- When you say:

I am attempting to use the form called "Member Intake" to create a user's singular Member post as well as connecting it to an existing group (if possible). If that needs to be a different form (where they can only select their own Member, not someone else's),

===>
As we have different relationship form to if you edit the relationship form:
- hidden link

And click on Members or Entities field, it offers you the option with "Filtering" section where you can select you want to display posts for those fields with any author or current author.

#2757223

I have created a page called "Link-Group" that has the post relationship form you made. But it doesn't seem to work properly.

I want the user to be able to link their own Member (one authored by the logged in user) with any Entity. So they can use the form many times. So I suppose that might be one-to-many form their perspective.

#2757631

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

On this page: hidden link

With relationship form - by default when the above page loaded with member dropdown do you want to select any member by default? or user should select member from the list of the member dropdown?

and same as what you would like to show with entities dropdown?

#2759133

They shouldn't be able to change the member dropdown. It should auto-select their own member (I would hide this behind a portal).

For the entities, they should be able to select any of them from the dropdown (which I'd prefer over the search box).

#2761810

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I see you created following members:
- hidden link

How to know or identify what member we should set selected when the following page with member dropdown:
- On this page: hidden link

#2761961

It should be the one authored by the currently logged in user. So if you create one, it should select that one only.
I'll have something in the backend to prevent them from creating a second, so it shouldn't be a problem to select the only one authored by the currently logged in user.

#2762732

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've set the option to use both legacy and block view:
- https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/

I've set the post author of the following post "Test Person" as "toolsetadmin":
- hidden link

Then I've created the following legacy view to get the post ID of the member post where current loggedin user is the author of that member post:
=> hidden link
Where as you can see I've added the following "Query Filter":

Post author filter
Select posts with the author the same as the current logged in user.

The above view will only return 1 entry (the return value will be the ID of member post) if such post is found otherwise 0.

[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=other][wpv-post-id],[wpv-item index=last][wpv-post-id]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found]0[/wpv-no-items-found][wpv-layout-end]

And then with the page you have "Link Group":
- hidden link

I've added the "Fields and Text" block and added the relationship form to it as given under:

[cred-relationship-form form='member-entities-many-to-many' parent_item='[wpv-view name="get-member-id-author-logged-user" cached="off"]']

Now, if you check I can see the member "Test Person" is selected when I visit the following page: - hidden link