Skip Navigation

[Resolved] Custom Dropdown Relationship per Post

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 5 replies, has 2 voices.

Last updated by Nigel 3 months, 3 weeks ago.

Assisted by: Nigel.

Author
Posts
#2732570

This is a complicated one and I need to know what the best approach is (taxonomies, fields, etc.).

I have 2 post types:
Members
Groups

They will be in a many-to-many relationship.

When a member signs up, they select what group they're a part of. Pretty simple.

But I also want them to select (as a dropdown) their TITLE in that group. And the YEAR they held that title.
The twist? Not all groups share the same set of titles.
So the Fencing Club could have Chairs. The Juggling Club might have Presidents. The Archery Club could have Commissioners.

I need it to be a dropdown and not just a text box.

What is the most logical way to get this done?
Taxonomies don't quite work because it changes from group to group. Does tying it to a relationship field and making it repeatable work? How can I get it to change the titles based on their selection of a group? Very much like how if you were shopping for a car, and you select HONDA, it will then give you only Honda models to choose from.

Any help is appreciated.

#2732876

Nigel
Supporter

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

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

Hi Sean

This is indeed a tough one.

Let's give the "field" we are talking about a name, i.e. "role".

A member joins a group and has a designated role in that group, but the available roles change from group to group.

The field has to be a relationship field because it is particular to the connection between member and group (e.g. John Smith could be President of the Juggling Club and could also be Secretary of the Archery Club while Jane Black could be Secretary of the Juggling Club etc. etc.).

So the challenge is that when connecting a member to a particular group, e.g. the Archery Club, only the roles relevant to that group are available.

This, for sure, would involve some code, it's not something that can be done within the UI.

There would be two parts to this.

The first is that you need to record somewhere what the roles available to the different groups are. In principle that would involve creating a field "Group roles" that includes all of the available roles. (The specifics of what field type would depend on the full implementation.)

That's kind of the easy part.

The next is that you would have a relationship field for the actual role, and somehow that field would need to be dynamic, such that depending on which group the member was being added to, the available options in the role field would be modified.

If the starting point was the group, and you were adding a member to it, then it's feasible that we know the group and so can modify the options available in the role field.

If the starting point was the member, and we were connecting to an existing group, that becomes trickier. I'm thinking here about the UI, and whether we are operating in the back end with PHP or the front end with JavaScript.

Before commenting more, I would need to know more about where this data is being added, what's the context? Back-end editing screens? Front-end forms? What's the starting point in the workflow?

Note, as indicated, this is going to require coding, and I can't do that for you, but I may be able to point you in the right direction if I have some more details.

#2733383
data-dependent.png

The current setup is that a user will access a frontend form (right now it is through Gravity Forms with the custom post type plugin enabled, but it might as well be Cred) to create their own Member entry. When they choose their Group, that ties into that relationship. Then we've got the custom Roles that they would choose (and Year, which is standardized).

There are like 40 groups btw.
An annoying (but maybe possible) way to do this is by doing a custom field group for each Group. Then do the "data dependent" option for display. That feels tedious, but maybe it would work.

#2734887

Nigel
Supporter

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

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

"When they choose their Group, that ties into that relationship."

So, you use Gravity Forms, and have a form to publish a Member post. The form includes a dropdown where you have listed the Groups as options.

Presumably you have PHP code that hooks into the form submission to handle connecting the Member to the selected Group. In which case you would also be populating relationship fields with the same code, including setting the Role relationship field. (See the API details for toolset_connect_posts: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts. That returns, amongst other things, the ID of the generated intermediate post used to store relationship fields, which you can use with add_post_meta to set the Role field value.)

So then the issue of which Roles to present when a user selects a Group becomes an issue internal to the form.

I expect that when defining the relationship between Groups and Members and specifying the Role relationship field, rather than a select field with a complete set of the available options, you can make it a Single Text field, because your users won't be accessing the back-end post edit screens where they would need to see a dropdown with a set of options. The Single Text field will be used to store the roles, such as "President", "Chairperson" etc., as free-form text, which is what would then be shown when outputting the field.

I am only partially familiar with Gravity Forms, but I know you can have conditional fields based on user choices. Can you set up Role fields (they would all want to use the same slug, e.g. role, but could have different labels, e.g. Archery Roles, Golf Roles, etc.) that are conditionally displayed depending on the choice of Group?

Managing the various options within the Gravity Form in that way doesn't sound like a bad way to go.

#2735235

I think I see what you're getting at. I can play around with it in Gravity Forms a bit.

But if you were to do it within Cred, is there anything different?

#2735665

Nigel
Supporter

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

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

Toolset supports relationship forms, specifically for connecting posts from either side of a many-to-many relationship, but it's not really relevant here, in that they are to connect existing posts. You want a form to add a new member post, then connect it to a group. Also, while the relationship forms can include relationship fields, these forms don't support conditional display in the same way that conventional forms do, so what I described above wouldn't work.

Which means the alternative to the Gravity Forms setup described above would be essentially doing the same with a regular Toolset Form to publish a new member post, the form including conditionally displayed dropdowns for the role, using code to connect to a group upon submission, as well as storing the relationship field.

In which case the choice becomes a simple preference between Toolset Forms and Gravity Forms. Toolset Forms are part of a suite of tools, while Gravity Forms is a dedicated form-building plugin, I could foresee the UI being a bit easier to work with in Gravity Forms, but it's a matter of personal preference.