Problem: I have two one-to-many post relationships that create a grandparent, parent, and child post. I have a Form that lets Users create child posts for a specific parent post. I would like to create a conditional group in the Form based on a field in the grandparent post.
Solution: Try this custom code in your child theme's functions.php file, or in a new snippet in Toolset > Settings > Custom code:
add_shortcode( 'ts-grandparent-field', 'ts_grandparent_field_func' ); function ts_grandparent_field_func( $atts ) { $a = shortcode_atts( array( 'grandparent-parent' => null, 'url-param' => null, 'field' => null, ), $atts ); if( !$a['grandparent-parent'] || !$a['url-param'] || !$a['field'] ) { return; } $parent_id = isset($_GET[$a['url-param']]) ? $_GET[$a['url-param']]: 0; if( !$parent_id ) return; $grandparent_id = toolset_get_related_post( $parent_id, $a['grandparent-parent'], 'parent'); if( !$grandparent_id ) return; return get_post_meta( $grandparent_id, 'wpcf-' . $a['field'], true); }
Then you can use it like this:
Class info: [ts-grandparent-field grandparent-parent="class-starting" url-param="parent_starting_id" field="class-info"][/ts-grandparent-field]
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 4 replies, has 2 voices.
Last updated by 6 years, 2 months ago.
Assisted by: Christian Cox.