Skip Navigation

[Resolved] Conditional for images with permission for multiple instances of the field

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/Karachi (GMT+05:00)

This topic contains 5 replies, has 3 voices.

Last updated by Waqar 9 months, 1 week ago.

Assisted by: Waqar.

Author
Posts
#2689040

Hello,

I have been following this ticket but I can't find a solution: https://toolset.com/forums/topic/image-gallery-repeating-image-if-there-arent-enough-to-fill-spaces/

I need to create a conditional for an image field with the active option to have more than one instance. I need to know if the field is empty or has an image.

He añadido el código personalizado y al añadir el shortcode en la vista siempre devuelve 0.

add_shortcode('get-image-field-count', 'get_image_field_count_fn');
function get_image_field_count_fn() {

$custom_fields_array = get_post_meta( get_the_ID(), 'wpcf-listing-images', false );

return count($custom_fields_array);
}

How can I do it?

Greetings and thank you

#2689060

Nigel
Supporter

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

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

Hi there

What is the context where you are using the shortcode?

The code itself looks okay, assuming that the context is correct for get_the_ID to return the post ID of a post that has values for a custom field whose slug is listing-images.

Maybe try returning the result of get_the_ID() to check it is the value expected.

#2689063

El contexto es que quiero una condicional para saber si un campo de imagen fuese repetible (activada la opción: ¿Campo único o se repite? Permitir varias instancias en este campo) De este modo, si el campo no contiene ninguna imagen no cargará nada.

Este es el código de la View:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="flexslider">
<ul class="slides">
<wpv-loop>
[add_video_to_slider slug="[wpv-taxonomy-slug]"]

/*COMIENZO DE LA CONDICIONAL PARA SABER SI EL CAMPO TIENE IMAGENES*/

  • [types termmeta='galleria-category' title='%%TITLE%%' alt='%%ALT%%' size='medium' resize='proportional' separator='
  • '][/types]
  • /*FIN DE LA CONDICIONAL PARA SABER SI EL CAMPO TIENE IMAGENES*/

    </wpv-loop>

    </div>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
    [wpml-string context="wpv-views"]No items found[/wpml-string]
    [/wpv-no-items-found]
    [wpv-layout-end]

    #2689133

    Hi,

    Nigel has a day off today, so I'll be following up on this ticket.

    If your goal is to add some content conditionally depending on whether the image type custom field is empty or not, you can use the conditional statement, as explained here:
    https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/

    For example:

    
    [wpv-conditional if="( $(wpcf-listing-images) ne '' )"]
    Image field is not empty!
    [/wpv-conditional]
    
    [wpv-conditional if="( $(wpcf-listing-images) eq '' )"]
    Image field is empty!
    [/wpv-conditional]
    
    

    regards,
    Waqar

    #2689136

    Hello Nigel,

    That is the basic conditional for an image field with the conditional for a single image. If you see the code I have sent and the explanation above, what I need is a conditional for when the image field has the option enabled to make it a field to add more than one image. The option in the field configuration is: Allow multiple instances in this field
    What is the conditional for this type of field?

    #2689431

    Thanks for writing back.

    The example conditional statement that I shared in the last reply should work for both types of image fields (single instance and multiple instances).

    Please test it and in case of any challenge, you're welcome to share temporary admin login details, along with the exact steps to see the issue.

    Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.