Skip Navigation

[Resolved] Setting conditions based on relationships

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 3 replies, has 2 voices.

Last updated by Christopher Amirian 1 year, 6 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2600921

Tell us what you are trying to do?
I am trying to show related fields on a post only if they are not empty. For example a "Person" may have a related "Chorus". If there is no related Chorus then I want to hide the Heading of that block.

Is there any documentation that you are following?
I don't see anything about relationships and conditions

Is there a similar example that we can see?

What is the link to your site?

hidden link

#2601189

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Let me understand what the scenario is.

You have a custom post type named Person and a custom post type named Chorus.

You used a relationship between the two posts most probably one to many. (Correct me if I am wrong)

Now you are on the page of the single Person and you want to show Choruses related to that post type.

If that is the scenario you need to create another view to show the Chrouses related to the Person and here is how to:

https://toolset.com/course-lesson/displaying-related-posts/

Now when it comes to show the items of the Course including the custom fields, it will show the related ones and you do not need to handle anything as the relation is done int he post level and not the sub items such as the custom field.

Thanks.

#2602933

Thanks for your reply.

Most of the relationships are many to many - for example, a person may be connected to several choruses, and a chorus may be connected to several people.

I understand how to display related posts, but I don't want the Heading to display if there is no related post. For example, I do not want the heading "related choruses" to appear if there is no chorus related to a person.

#2603755

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Now I see what you mean.

Please kindly use the method below to achieve what you want:

https://toolset.com/forums/topic/display-related-posts-only-if-there-are-any/#post-1913451

A summary:

- Move the headline inside the view that you use to show the related post.
- Add a conditional to detect the number of results and not show if the result is 0.

Thanks.