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
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.
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.
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.