I am trying to:
Use the custom shortcode provided here https://toolset.com/forums/topic/conditional-output-based-on-post-relationships/ and it's not working when there is more than one relationship.
Link to a page where the issue can be seen:
hidden link (You'll need a login. It also just shows an empty team information card because the conditionals using the shortcode are reading as false, when in fact they are true, there's just more than 1 relationship.
I expected to see:
my views loading correctly. there's one that displays departments. If I use a different content template without the shortcodes, it works fine.
Instead, I got:
The conditionals errantly read as false, and the views did not load.
Hi, I'll be glad to take a look if you provide login credentials in the private reply fields here.
These credentials don't seem to work for me. Can you check? Is there a leading or trailing space in the password?
The conditionals errantly read as false, and the views did not load.
Which conditionals, specifically? Based on the logic provided, the two conditionals using the custom shortcode correctly read as false. You can see the debug information now on the site. Both of these conditionals are returning false because they are testing for values equal to 1. The shortcode returns the number of connected posts, which in these 2 specific cases is not 1. You can verify this in Ryan's Staff Member post: hidden link
1. There are 2 staff member / department connections, not 1. Production and Production/History are both connected to Ryan.
2. There are 0 leaders / staff members connections, not 1. Ryan has no connected leadership posts.
So you can see neither of these values is 1, so both conditionals are accurately reading false. Maybe I don't understand what you would like to accomplish here?
The custom shortcode is supposed to test for the existence of the relationship. That's what I'm trying to do. So if the profile does not have departments, it should read as false. If the profile has 1 department, it should read as true. (it does here.) If the profile has more than 1 department, it should also read as true. If the profile is associated with a leadership, (this one doesn't happen to be), but say Kathy Bissen is, it should also read as true. I don't think there are leaders in more than one leadership.
But the glitch I am encountering is I want to test for 1 or more than one.
--Sam
The custom shortcode is supposed to test for the existence of the relationship.
Not exactly, let me explain that a bit. The custom shortcode Nigel provided is supposed to return the number of related posts. The conditional tests that number based some comparison logic. Nigel's conditional tests if that number is 0. This is the negative case - what you want to show if there are no related posts found.
The postitive case conditional (if related posts exist) should test if the shortcode returns a value greater than or equal to 1, because more than one related post can exist. The syntax for that comparison is gte 1 instead of eq 1.