Skip Navigation

[Resolved] Conditional for empty Wysiwyg field on a post relationship

This support ticket is created 2 years, 9 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 11 replies, has 2 voices.

Last updated by Arno 2 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#2366149

Hi,

I have a Wysiwyg field on a post relationship. In a view loop, I have a Fields and Text block where I need to output the field value and some HTML unless the field is empty.

I tried this:
<p>[wpv-conditional if="(NOT(empty('[types field="travel-description" item="@travel-relation.intermediary" output="raw"][/types]')))"]not empty 1[/wpv-conditional]</p>

However, this will always output "not empty 1", even is the field is empty.

I also tried this with the same result:
<p>[wpv-conditional if="('[types field="travel-ticket-activity-included-description" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]') ne ''"]not empty 1[/wpv-conditional]</p>

What's the correct way to do this?

Thanks!

#2366513
text-editor.jpg

Hello,

I have tried the same codes you provided above in my localhost with a fresh WP installation + the latest version of Toolset plugins.
It works fine, please check these in your website:
Edit those intermediate posts, find the custom Wysiwyg field, switch to Text editor mode, see my screenshot text-editor.jpg, make sure it is empty value

#2366535

Hi Luo,

That's strange, I have even deleted the relationships and created them again, and entered nothing in that field in one of the relationships. I also checked in text editor mode. There's nothing in the field.

What else may cause this? The relation has 3 fields in total: 2 wysiwyg and 1 number. A conditional on the number field works fine.

I can try to reproduce this in a simpler setup in a staging site.

#2366537

Please provide the staging website credentials in below private message box, also point out the problem post URL and view URL, thanks

#2367533

I assume we are talking about this content template "Tmp WYSIWYG":
hidden link

I have tried these in your website:
1) Edit above content template, find and edit the "Fields and Text" block, add below lines to debug the result:

[wpv-post-link]
<hr />
123
[types field="travel-ticket-activity-included-description" item="@travel-ticket-activity-included-relation.intermediary" output="raw"]
456789
<hr />

2) Test it in frontend:
hidden link
I don't see the 56789 in frontend, so your website is abnormal, there might be other compatibility issues, I need your permission to deactivate other plugins/theme, please backup your website first.

#2367569
view-loop-output-html.jpg

Yes, that's the template. Please find my explanation in the previous private post.

I see what you tested and how the output does not make sense. I checked the outputted HTML and it contains a closing p tag in a weird spot. Please see attached. This tag is not in the WYSIWYG field. I don't know where it is coming from.

The only activated plugins are Toolset Access/Blocks/Maps/Types, Wordfence and "Temporary Login Without Password" to give you access. Feel free to deactivate whatever you like. It's a staging site to test with.

#2369143

Please try to modify the shortcodes as below:

[wpv-conditional if="('[types field="travel-ticket-activity-included-description" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]' EQ '')"]
not empty 1: [types field="travel-ticket-activity-included-description" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]
[/wpv-conditional]

[wpv-conditional if="('[types field="travel-ticket-activity-included-description" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]' EQ '' evaluate='false')"]
empty value
[/wpv-conditional]

I have tried it in your website, it works fine

More help:
https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-types-checkboxes-field-for-non-empty-value

#2369453

Thanks, but I don't understand yet.

In the first line of your example, why is " EQ '' " used to display "not empty 1"? If it's equal to '' it is empty, right?

Either way, the result on the page hidden link doesn't seem to be right. The loop displays 3 tickets. The field travel-ticket-activity-included-description is empty for the relation with ticket 1 and 2. Yet only "not empty" is displayed for all tickets.

#2369859

Please try to modify the shortcodes as below, and test again:

[wpv-conditional if="( $(wpcf-travel-ticket-activity-included-description).item(@travel-ticket-activity-included-relation.intermediary) eq '' )"]
empty
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-travel-ticket-activity-included-description).item(@travel-ticket-activity-included-relation.intermediary) ne '' )"]
not empty 0: [types field="travel-ticket-activity-included-description" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]
[/wpv-conditional]

You can setup above codes with legacy editor, for example:
Create a content template, edit with classic editor, click button "conditional output"

#2370905

Thank you, I now have it working!

It is pretty tricky though. A few findings:

1. If the code contains tabs it will break. I think even a line break caused issues at some point.

2. This works for a number field:

[wpv-conditional if="('[types field="travel-ticket-activity-included-discount-percentage" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]' gt '0')"]

But if I replace it with this, it does not work:

[wpv-conditional if="( $(wpcf-travel-ticket-activity-included-discount-percentage).item=(@travel-ticket-activity-included-relation.intermediary) gt '0')"]

But that's the syntax I got from the legacy editor inside a view. I don't understand why one works and the other does not.

For reference, here's the code that works ok at the moment:

[wpv-conditional if="('[types field="travel-ticket-activity-included-discount-percentage" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]' gt '0')"]
[wpv-conditional if="($(wpcf-travel-ticket-activity-included-description).item(@travel-ticket-activity-included-relation.intermediary) ne '' )"]
[types field="travel-ticket-activity-included-description" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]
[/wpv-conditional]<p>Discount: [types field="travel-ticket-activity-included-discount-percentage" item="@travel-ticket-activity-included-relation.intermediary"][/types]%</p>[/wpv-conditional]
[wpv-conditional if="($(wpcf-travel-ticket-activity-included-discount-other).item(@travel-ticket-activity-included-relation.intermediary) ne '' )"]
[types field="travel-ticket-activity-included-discount-other" item="@travel-ticket-activity-included-relation.intermediary" output="raw"][/types]
[/wpv-conditional]
#2371465

The "item" attribute in wpv-conditional shortcode should use double quotes and without "=", like this: item("...")
You can not use it as: item=(...), for example:

[wpv-conditional if="( $(wpcf-travel-ticket-activity-included-discount-percentage).item(@travel-ticket-activity-included-relation.intermediary) gt '0' )"]
...
[/wpv-conditional]

As I mentioned above, you can setup the wpv-conditional shortcode with classic editor in content template.

#2371577

You're right, now that part works too. My issue is resolved now. Thank you!