[Resolved] Conditional check if there are related posts
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to test whether there are any related posts using a conditional shortcode?
Solution:
You would want to register a custom shortcode that returns how many connected posts there are in the specified relationship, which you can compare to zero in your conditional shortcode.
I have a parent post 'listing' with child post 'relatedproject'. They are connected via the relationship 'listing-related-project'. I am trying to conditionally output some content on the Content Template for Listing where there are no related child posts.
I've registered the shortcode [child-exists] in Settings and I've registered the function 'child_exists_func' for use in conditional evaluations in settings.
And I have tried the following shortcodes in my Content Template:
It outputs the number of posts related to the current post for a relationship you specify with the "relationship" attribute, e.g.
[connections relationship="project-task"]
If you want to use it in a conditional shortcode (where you test for zero), don't forget to register the connections shortcode first at Toolset > Settings > Front-end Content