Skip Navigation

[Waiting for user feedback] Using Grandparent field in a conditional

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.

This topic contains 1 reply, has 1 voice.

Last updated by Christopher Amirian 1 hour, 46 minutes ago.

Assisted by: Christopher Amirian.

Author
Posts
#2839247

Tell us what you are trying to do?
I have a data structure as follows: Events -< Award Groups -< Awards. Event has a custom field 'Status' ("Nominations ¦ Shortlisting ¦ Judging ¦ Winners"). I wish to put a conditional block on the Award Single Page that displays differently, depending on the value of 'Status', i.e. depending on a custom field of the grandparent. I am using Legacy Views and shortcodes because I am displaying nested Views. Please advise, thanks.

Is there any documentation that you are following? Google found a post in your help files, but it returns a 404 when clicking the link to your site.

#2839316

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Welcome to Toolset support. Yes, you can do this, but you’ll need one small custom shortcode to “jump” from Award → Award Group → Event, then use it in a [wpv-conditional].

1) Add a shortcode to get the grandparent Event ID

Add this PHP (Toolset → Settings → Using Toolset to add custom code or in a custom plugin) and adjust the relationship slugs:

function get_grandparent_id_func( $atts ) {
    $a = shortcode_atts( array(
        'postid'         => 0,
        'parentrel'      => '',
        'grandparentrel' => '',
    ), $atts );

    $parent      = toolset_get_related_post( $a['postid'], $a['parentrel'] );
    $grandparent = toolset_get_related_post( $parent, $a['grandparentrel'] );

    return $grandparent;
}
add_shortcode( 'get-grandparent-id', 'get_grandparent_id_func' );

I have got the idea for the code above from here.

Then register this function and shortcode under Toolset → Settings → Front-end Content:
https://toolset.com/documentation/programmer-reference/views/using-custom-functions-in-conditions/

2) Use it in a conditional on the Award single

On the Award single View/template, use something like:

[wpv-conditional if=" '[types field='status' item='[get-grandparent-id postid='[wpv-post-id]' parentrel='awardgroup-award' grandparentrel='event-awardgroup']' output='raw'][/types]' eq 'Nominations' "]
  … HTML for Nominations state …
[/wpv-conditional]


- Replace awardgroup-award and event-awardgroup with your relationship slugs.
- Replace status and Nominations with your actual field/values.

For more information about conditional outputs:
https://toolset.com/forums/topic/display-content-conditionally-for-category/

Thanks.