Skip Navigation

[Gelöst] Using relationship data as a conditional group field in a form

This support ticket is created vor 1 Jahr, 11 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 7 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von leilaG vor 1 Jahr, 10 Monaten.

Assistiert von: Minesh.

Author
Artikel
#2530233

Hello,

We have a custom post type 'Weekly menu' that has a relationship to 'Locations'

In the post form for Weekly menu, we'd like to conditionally show some fields depending on the 'Location' relationship. Is that possible?

#2530343

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

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

Hi there

Conditional display groups in a form are JavaScript based and can change visibility depending on selections made in the form. There is no possibility to use these based upon data from related posts.

But maybe conditional shortcodes would meet your needs? They would conditionally output some content at the time the form is rendered (which could include only adding some fields to the form based upon the condition being met).

To use those you would need to the advanced form editor (i.e. edit the markup and shortcodes directly), where you could insert wpv-conditional shortcodes that checked values from related posts.

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional

Note, though, that there can only be a single related post, e.g. it would work for a form publishing child posts that referenced a field from the parent (there can be only one parent), but not for a form publishing parent posts that referenced a field from a child post (because there can be many child posts, so which one should it reference?).

In the former case your wpv-conditional shortcode can test the output of a shortcode which outputs the desired field (e.g. a types shortcode), adding the item attribute to specify that the origin post is a related parent.

Here's an example of the format used to output a field "status" from the parent of a project-tasks relationship:

[types field='status' item='@project-task.parent'][/types]
#2531053
conditional-group.png

Thanks for the solution.

Instead to make it simpler, I added a radio button field with 2 options but it doesn't seem to work for the edit forms (image attached) it's not showing any of the fields when I put them inside the conditional group.

These have been tagged with 'Standard' Radio button
versteckter Link
versteckter Link
versteckter Link

This has been tagged with 'Edinburgh' radio button
versteckter Link

#2531079

Minesh
Supporter

Sprachen: Englisch (English )

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

- Can you please share screenshot of how you configure the radio button field with what option and what value?

#2531103
field.png
type selected.png

There you go, let me know if you need anything else.

#2531121

Minesh
Supporter

Sprachen: Englisch (English )

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

The field configuration seems ok to me.

Can you please share admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.

#2531137

Minesh
Supporter

Sprachen: Englisch (English )

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

The issue was the radio field "menu-type" should be available on the form.

With you form as you can see - I've added the "Menu type" field:
=> versteckter Link

And with the form's CSS box I've added the following custom CSS to hide that field:

.wpb_wrapper .row:nth-child(3)  {display:none;}

Can you please confirm it works as expected now:
- versteckter Link

#2531149

Works perfectly. Thank you!