Skip Navigation

[Resolved] related field show post title of current post rather than blank for th

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

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.

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 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#556188

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:

#556210

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?

#556393

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

#556972

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/

#557643

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?

#557883

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/