Skip Navigation

[Resolved] How to display a link to parent CPT conditionally?

This support ticket is created 6 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1088691

I have a CPT called "Articles" and another CPT called "Magazines".
Some articles are standalone articles, and some are children to magazines in a many-to-many relationship.

I can easily display a list of articles that relate to a certain magazine. please check the unordered list at the bottom of this post:
hidden link

now I want to add a view to the "articles" layout to show a link back to the parent magazine, but only when the article is a child to a magazine.

I was able to achive something similar between another pair of CPTs (books and chapters) using this code:

[wpml-string context="Chapters Parent book title" name="Chapters Parent book title"]This is a Chapter of the Book: [/wpml-string][wpv-post-link id='@book-chapter-one-to-many.parent'].

However, this will always show in the layout as there are no chapters that are not related to books, but for articles/magazines you can have standalone articles and magazine related articles.

So my question is: how to create a view to show parent magazine only when the article is related to a magazine only?

If i used my code above, then on standalone articles, i will have a meaningless sentence appearing saying: "this article is a part of magazine: (nothing)."

Thanks a lot.

#1089224

Hello,

You just need to move the text "this article is a part of magazine..." into the related magazine post view, for example:

1) Create a post view, list magazine posts, filter by the
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

2) In "Loop Output" section, insider shortcode [wpv-items-found]... [/wpv-items-found], display the text "this article is a part of magazine...".
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-items-found
Meta HTML wrapped in [wpv-items-found][/wpv-items-found] will be output if there are any posts | taxonomies | users returned by the View.