Skip Navigation

[Resolved] How to link to Parent from a View only IF on exists, otherwise link to post

This support ticket is created 5 years, 1 month 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by katrina 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1362345

Tell us what you are trying to do? link from a view to parent posts only if a parent exists

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

- I have two custom post types with parent and child relationship: Workshops (Parent) and Series (Child) (I hope I did this correctly in Toolset)
- On a page of my site i display a view which is a list of both Workshops and Series, and in the View Loop i have a link that should take thw user to the correct post. If the item in the View Loop is a "Series", then I want the link to go to the Parent Workshop instead of the Series post itself, but if the item in the View Loop is a Workshop (i.e. it doesn't have a Parent), then I want the link to go to itself.
- Is this possible without conditional output?

I have tried the following :

click for more details

and

click for more details

However, it doesn't work. The links always go to the post itself, even if the child has a parent.

#1362403

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to use the following code and try to resolve your issue.

<a href="[wpv-post-url item='@your-relationship-slug.parent'][/types]">click for more details</a>

where;
- Replace your-relationship-slug with your original post relationshp slug.

More info:
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/#2-creating-a-content-template-for-the-parent-post

#1362413

Hi Minesh - thank you, this helps get part of the way there!

It does work in linking to the parent (Workshop) if the item in the view loop is a child (i.e. a Series post type).

But if the item in the view loop is a Workshop post type, it doesn't link anywhere. I need it to link to the Workshop post itself if it's a Workshop.

#1362443

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Actually - I need to know how you setup the view and after that I'll be in the position to guide you in the right direction.

Can you please share information about how you setup your view? Please share the code or screenshot.

#1362445

In my view, it displays a list of Workshops and Series post types.

Currently i have this workaround in my loop, which works:

[wpv-conditional if="( '[wpv-post-type]' eq 'workshop' )"]<a href="[wpv-post-url]">More Information</a>[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' ne 'workshop' )"]<a href="[wpv-post-url item='@workshop-workshop-series.parent']">More Information</a>[/wpv-conditional]

But i am wondering if I can make this simpler, without using two conditional statements?

#1362447

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

This is exactly I was supposed to offer you. You are in the right direction and thats the way to display that.

#1362451

Ah ok... thanks!!