Skip Navigation

[Resolved] Testing an image field for empty values not working

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

Problem:
A taxonomy has an image custom field. When it comes to displaying the image a conditional shortcode is used to first test if the image value is set, but it is not working.

Solution:
An image field by default outputs an img tag, which seems to break the conditional test. Adding the output="raw" attribute to the shortcode just outputs the url and fixes the problem.

This support ticket is created 5 years, 11 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by arisG 5 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1234608

Hello,

we have a term custom field with name "image" and type image. I have two taxonomies , one with image on it and one without image.

I use the following conditions and the taxonomy without image correctly show the message "Empty Field image". When i select the taxonomy with an image the "Not Empty Field Image" doesn't appeared.

[wpv-conditional if="( '[types termmeta='image'][/types]' eq '' )"] Empty Field image[/wpv-conditional]
[wpv-conditional if="( '[types termmeta='image'][/types]' ne '' )"] Not Empty Field Image [/wpv-conditional]

Regards,
Aris

#1234952

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

Sorry for the slow response to your ticket which I have just picked up.

I tested this locally and it worked correctly.

The GUI doesn't let you insert such a condition, you need to enter it manually.

The easiest way to do that is to insert the term custom field using the Fields and Views button then copy and paste the resulting shortcode as the condition in the wpv-conditional shortcode.

So the only difference in my version compared to yours is the raw output attribute, as we are just checking whether the URL is defined or not.

So mine looks like this:

          [wpv-conditional if="( '[types termmeta='status-icon' output='raw'][/types]' ne '' )"]
          We have an image
          [/wpv-conditional]
          [wpv-conditional if="( '[types termmeta='status-icon' output='raw'][/types]' eq '' )"]
          We do not have an image
          [/wpv-conditional]

I assume you are using this in a View to display taxonomy terms, is that right?

#1235288

Hello Nigel,

I was using the field in a WordPress Archive and the custom Term field is not in the Fields and Views button. I add the output='raw' param and it works!

Thank you!