I am trying to:
I have a link between the trips and host families. In a view of the trips I am showing the host family linked to that trip. The last name of the host family is post title. when the host family is populated in the the trip content type it works fine showing the host family that is linked to that trip. When the host family is not populated it is show the post title for the trip
Link to a page where the issue can be seen:
I expected to see:
Instead, I got:
Hello, I will try to help. You mentioned there is a link between Trips and Host Families. What does this mean? Is there a parent / child relationship between Trips and Host Families?
Here is some information about displaying fields from parent and child posts:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
If this is some other type of link, please describe in detail how these posts are linked. Please provide more information about how the post title is displayed on the page. Is it in the post body? Is it in a Content Template? A Layout? What code are you using?
<div class="col-md-12 view-item-col-heading view-item-name">Host Family: </div>
<div class="col-md-12 view-item-details">[wpv-post-title id="$host-family"]</div>
the host family is the parent of the trip, as in one host family can host many trips.
When the host link field is populated it show the correct data is shown, however when the host link field is not populate instead of it appearing blank is show the post title for the current trip post. It looks like a bug.
I see, thanks for the clarification. If the parent host family is not set, then the [wpv-post-title] shortcode (and most other shortcodes like this) will fallback to display information from the current post. This is how it's designed to work, so it's not exactly a bug. If you want to hide the title when the parent isn't linked, you should use conditional HTML to show [wpv-post-title] when the linked parent post ID does not match the current post ID. If no parent is linked, the post ID will fallback to the current post, like the title shortcode. Try this:
[wpv-conditional if=" '[wpv-post-id]' ne '[wpv-post-id id='$host-family']' "]
<div class="col-md-12 view-item-details">[wpv-post-title id="$host-family"]</div>
[/wpv-conditional]
More about conditional HTML here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
This is not a good feature and I cannot see why you would want this to happen unless it is for a specific solution rather than all cases.
Can you tell me how to check if the link field is blank which would be a slightly more reliable solution I think?
I don't understand why you feel this isn't reliable or a good approach. The only way it would stop working is if [wpv-post-id] and [wpv-post-id id='$parent-slug'] become different when the parent is not defined. That makes no sense, and will not happen, because it's illogical and [wpv-post-id], the id attribute, and parent operators are documented features. This approach is reliable, but if you want an alternative, you can write custom PHP to access the "_wpcf_belongs_host-family_id" postmeta value from the child post. This is how the link between parent and child is established. There's an example at the bottom of the page here:
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/