Skip Navigation

[Resolved] Conditional issue with multiline custom field

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

Problem:

I have a custom field named "Artwork Dimensions" that is a multiline input field.

In the Content Template that belongs to the View where the Artwork Dimensions field is displayed, I'm using a conditional to test whether it's empty, and if it isn't empty, to display the field:

Solution:

I suggest you try to modify those codes as below:

https://toolset.com/forums/topic/conditional-issue-with-multiline-custom-field/#post-1365213

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/functions/#textarea

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

Last updated by josephC-5 5 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1365081

Hi there,

A have a custom field named "Artwork Dimensions" that is a multiline input field.

In the Content Template that belongs to the View where the Artwork Dimensions field is displayed, I'm using a conditional to test whether it's empty, and if it isn't empty, to display the field:

[wpv-conditional if="( '[types field='artwork-dimensions' output='raw'][/types]' ne '' )"]
  <p class="artist_artwork_detail_dimensions">[types field='artwork-dimensions'][/types]</p>
[/wpv-conditional]

This conditional doesn't seem to be working. Am I doing something wrong?

Thanks!

Saul

#1365213

Dear Saul,

I suggest you try to modify those codes as below:

[wpv-conditional if="( '[types field='artwork-dimensions' output='raw' suppress_filters="true"][/types]' ne '' )" debug="true"]
  <div class="artist_artwork_detail_dimensions">[types field='artwork-dimensions'][/types]</div>
[/wpv-conditional]

And test again.

More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/#textarea
suppress_filters:
'true' | 'false' (default)
If suppress_filters=’true’, all third party (non WordPress) filters hooked into the_content filter will be removed,

#1365737

Luo,

Thanks for your response. I replaced my code with your code, and 1) the comparison still failed and 2) there was no debugging output whatsoever.

I ended up solving the problem by changing the syntax. Here's the revised and working snippet:

[wpv-conditional if="( $(wpcf-artwork-dimensions) ne '' )"]
  <div class="artist_artwork_detail_dimensions">[types field='artwork-dimensions'][/types]</div>
[/wpv-conditional]

My question is, why does this syntax work and the shortcode syntax not work?

Thank you!

Saul

#1365951

There should be some compatibility issue in your website, some plugins/theme will apply their custom filters into the_content filter, it will change the textarea field's output, which does not existed in my localhost with a fresh wordpress installation.

I suggest you check the compatibility problem:
please deactivate all other plugins, and switch to wordpress default theme 2019, deactivate all custom PHP/JS code snippets, and test again

#1367001

Luo,

Thanks for your response. I won't have time to follow the steps you listed to track down the root of this issue right now, but I do have a follow-up question: can you explain the difference between the two syntactical options for referencing custom fields inside conditionals?

[types field='artwork-dimensions'][/types] vs. $(wpcf-artwork-dimensions)

Thank you!

Saul

#1367037

Types shortcode [types field='artwork-dimensions'][/types] will output the textarea field value applied the_content filter hook:
https://developer.wordpress.org/reference/hooks/the_content/

So other plugins/theme can take effect on the output result.

But $(wpcf-artwork-dimensions) does not apply the_content filter hook.

You can add debug="true" attribute in wpv-conditional shortocde to compare the difference. see our document:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

debug (optional): it can be set to true or false and controls whether to display debug information for administrators.

#1367661

That makes sense. Thanks for the link to the documentation, Luo!

Saul