[Resolved] Conditional output for non-empty vs. empty related wpv-post-link

This thread is resolved. Here is a description of the problem and solution.

Problem:

There is a small number of cases where the relationship (deliberately) does not exist. I would like, in these cases, to provide generic text to note this.

Solution:

If the relationship (deliberately) does not exist, the shortcode [wpv-post-id id="$ecotypes-main-theme"] will output the current post ID, so you can use it to compare with shortcode [wpv-post-id], for example:

[wpv-conditional if="( '[wpv-post-id id="$ecotypes-main-theme"]' eq '[wpv-post-id]' )"]
relationship (deliberately) does not exist.
[/wpv-conditional]

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

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.

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 1 year, 8 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#950566

Tell us what you are trying to do? I have the following code that works successfully in most cases with a related post title:

[wpv-post-link id="$ecotypes-main-theme"]

But there is a small number of cases where the relationship (deliberately) does not exist. I would like, in these cases, to provide generic text to note this.

Is there any documentation that you are following? Yes, I am looking at your general conditional help page here:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/

and your empty/non-empty conditional page here:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

I could simply write two conditionals, one if not empty (most cases) and one if empty (the few cases). But I can't figure out how to refer to the title field of the related post, as it is a default post field (checked in Types) and it is a related field as well.

Is there a similar example that we can see? I haven't encountered a similar example in my uses of Toolset to date.

What is the link to your site? hidden link. Look for "Related Main Theme" toward top, where, you will see that Views is a bit confused with this shortcode, and simply outputs the wpv-post-link for the existing post, not its related (ecotypes-main-theme) post.

#951173

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hello,

If the relationship (deliberately) does not exist, the shortcode [wpv-post-id id="$ecotypes-main-theme"] will output the current post ID, so you can use it to compare with shortcode [wpv-post-id], for example:

[wpv-conditional if="( '[wpv-post-id id="$ecotypes-main-theme"]' eq '[wpv-post-id]' )"]
relationship (deliberately) does not exist.
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

#951442

Yes, this works, thanks. For others' reference if helpful, my final conditional code:

[wpv-conditional if="( NOT('[wpv-post-id id="$ecotypes-main-theme"]' eq '[wpv-post-id]') )"][wpv-post-link id="$ecotypes-main-theme"][/wpv-conditional][wpv-conditional if="( '[wpv-post-id id="$ecotypes-main-theme"]' eq '[wpv-post-id]' )"]N/A[/wpv-conditional]

Jim P.

#951660

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

You are welcome