Skip Navigation

[Resolved] Image field delete

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 2 voices.

Last updated by alvaroG 6 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#533441
image-field-empty.png
image-data-still-on-frontend.png
image-data-on-frontend.jpg
image-field-empty.png
image-field-empty-cant-delete.png
image-data-still-on-frontend.png

I am trying to: create an image repeating field that only shows on frontend if there's an image attached. But if I delete images attached to the post with that image field, there's always a blank field

I visited this URL: local development, not yet online. You can see the template part code to show the image data on frontend here: hidden link

I expected to see: image data should only get on frontend if there's an image attached

Instead, I got: image data on frontend even when there's no image attached

#533480

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alvora,

Thank you for contacting our support forum.

Actually what you need to do for this is to create a conditional statement that will display this section only if there are images in the field.

To do this have a look at the link below.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

Please let me know if this helps.
Thanks,
Shane

#533483

Hi Shane,

Thank you for your reply.

In fact, the link didn't help. It only shows shortcodes, I'm using php to show my data in frontend.

You can see here hidden link that I used common conditional to assess for empty field. The problem is the field is not empty, although I've deleted all the images. Therefore, no image is shown but the code that wraps the image is.

I've seen several entries in the forum about this issue, and no definitive answer on how to solve it.

Can you point me to a code solution instead of shortcodes?

Thanks.

Alvaro

#533486

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alvaro,

Could you add this to your code right after line 3

var_dump($galeria_imagens);

I would like to know the output given when the field is empty.

Thanks,
Shane

#533660
Screenshot 2017-06-07 10.22.41.png

Hi Shane,

When I add the var_dump code, it prints like this:

array (size=1)
  0 => string '' (length=0)

Thanks.

Álvaro

#533808

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alvaro,

Thanks so i see that even though the array is empty, its still giving us a value at the 0 index.

So to work around this we can check the 0 index to see if there is an actual value there and then do our conditional statement around that.

Evaluate the 0 index against an empty string.

Thanks,
Shane

#533817

Evaluate the 0 index against an empty string.

Can you give me an example on how to do that, please?

Thanks.

Álvaro

#533838

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alvaro,

You should be able to do it by doing this.

 if (!empty($galeria_imagens[0])): 

Please let me know if this helps.

Thanks,
Shane

#533868

It seems to have worked!

Thanks a lot Shane!

Álvaro

#534195

Hi again Shane,

Just a quick question regarding the code above: if I want to limit the field presentation to 4 images, what should I do?

Thanks.

Álvaro

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.