Tell us what you are trying to do? I've got two post types: an Essay and an Author. When viewing an Essay page, I want to display information related to the Author. I know I can display fields using the syntax [types field='field' item='@author.parent'][/types]. I'd also like to use conditional syntax that references the parent post. The pseudo-code below doesn't seem to work:
[wpv-conditional if="( $(wpcf-title) ne '' )"]
<p>[types field='title' item='@faculty-author.parent'][/types]</p>
[/wpv-conditional]
Is there any documentation that you are following? No
Is there a similar example that we can see? No
What is the link to your site? hidden link
Hello,
You can use the Types shortcode within attribute "if", for example:
[wpv-conditional if="'[types field="title" item="@faculty-author.parent"][/types]' ne '' )"]
<p>[types field='title' item='@faculty-author.parent'][/types]</p>
[/wpv-conditional
More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/
This is exactly what I was looking for. Thanks, Luo!
Uh oh, I may have spoken too soon.
Neither the syntax that you'd provided nor the instructions for checking for the existence of a parent post at https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-if-a-parent-exists, worked on my site. I'm pretty sure I've done something wrong, but I'm not sure what.
Here are both versions of my code:
#1 checking for the first name field of the parent post.
[wpv-conditional if="'[types field="first-name" item="@faculty-author.parent"][/types]' ne '' )"]
<p>By <a href="[wpv-post-url item="@faculty-author.parent"]">[types field='first-name' item='@faculty-author.parent'][/types] [types field='last-name' item='@faculty-author.parent'][/types]</a>, [types field='title' item='@faculty-author.parent'][/types]</p>
[/wpv-conditional]
#2 checking for a parent post ID.
[wpv-conditional if="(NOT(empty($(_wpcf_belongs_faculty_id))))"]
<p>By <a href="[wpv-post-url item="@faculty-author.parent"]">[types field='first-name' item='@faculty-author.parent'][/types] [types field='last-name' item='@faculty-author.parent'][/types]</a>, [types field='title' item='@faculty-author.parent'][/types]</p>
[/wpv-conditional]
Here's a test post: hidden link
The layout I'm modifying is the "Template for Essays": hidden link. The code is in the first row ("Subpage Image, Written by, Published on").
Can you take a look?
Thanks for the details, there is an extra ")" in my previous answer, I have modified it from:
[wpv-conditional if="'[types field="first-name" item="@faculty-author.parent"][/types]' ne '' )"]
To:
[wpv-conditional if="'[types field="first-name" item="@faculty-author.parent"][/types]' ne '' "]
Please test again, check if it is fixed or not.
Luo, thanks for your reply, and for finding the error in my syntax.
I also discovered that the reason the comparison wasn't working is because, when no Author is associated with the Essay, the value of [types field="first-name" item="@faculty-author.parent"][/types] wasn't the empty string, it was one blank space (" "). Here's the updated working code:
[php]
[wpv-conditional if="'[types field="first-name" item="@faculty-author.parent"][/types]' ne ' ' "]
[php]
Is that supposed to be correct?
Thanks again!
No, it is not supposed to be correct, unless you have saved a space ' ' in the "first-name" field.