Skip Navigation

[Resolved] Grab Parent Taxonomy in a Cred Form

This support ticket is created 2 years, 11 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 1 reply, has 2 voices.

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

Assisted by: Luo Yang.

Author
Posts
#2250157

Parent Post Type: Trip
Child Post Type: Traveler

New Travelers are created using a URL string, like website/join-trip/?parent_trip_id=569

Both post types have a "Group" taxonomy.
I want to duplicate that taxonomy from the parent into the child (on that cred form). I've tried a number of things that don't work, like:
[cred_field field='group' force_type='taxonomy' output='bootstrap' display='select' single_select='true' value='[wpv-post-taxonomy type="group" format="id" item="@trip_attendee.parent"]']

When I use: Group: [wpv-post-taxonomy type="group" format="name" item="[wpv-search-term param="parent_trip_id"]"]
it spits out the correct group, but how can I populate the dropdown correctly so that when the user submits, it'll have the correct group selected?

Do I need to embed the cred form in a view to get it to work? That's something that was required for some of my older issues.

#2250541

Hello,

The shortcode "value" attribute of shortcode [cred_field] won't work for taxonomy field, see our document:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field

value. Optional
...
Does not apply to all field types, e.g. taxonomies.

You might consider custom codes, for example, after user submit the child post form, use action hook cred_save_data to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
In this PHP function, get the related parent post ID:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
Get the parent post taxonomy "group" setting:
https://developer.wordpress.org/reference/functions/wp_get_object_terms/
Setup the child post taxonomy "group" setting:
https://developer.wordpress.org/reference/functions/wp_set_object_terms/

For your reference.