Skip Navigation

[Resolved] Relationships shortcode for connections not returning true with many relationshi

This support ticket is created 5 years, 9 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.

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 5 replies, has 2 voices.

Last updated by Christian Cox 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1230505

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.

#1230692

Hi, I'll be glad to take a look if you provide login credentials in the private reply fields here.

#1230722

These credentials don't seem to work for me. Can you check? Is there a leading or trailing space in the password?

#1230956
Screen Shot 2019-04-15 at 9.39.14 AM.png

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?

#1230966

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

#1231045

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.