Support

Account

Home Forums Add-ons Flexible Content Field Flexible Content count field (gallery)

Unread

Flexible Content count field (gallery)

  • Hello everyone,

    I have created a simple Snippet that works normally for a regular field and returns the number of photos in the gallery and looks like this:

    function numberofphotos(){
    $photos = count(get_field(‘gallery’));
    return $photos;
    }
    However, as I already mentioned, it only works with a separate field. But when I use gallery field when creating FLEXIBLE FIELD it doesn’t work anymore.

    To give an idea, I created a FLEXIBLE FIELD called “flexible_content” and in it I created a layout called “layout_gallery” and within that layout I create a “gallery” field.

    But I don’t get the relevant count back using the count() function. It’s either 0 or 1, depending on how I’m trying to enter the field names into the count() function.

    I tried writing a function like count(get_field(‘flexible_content_layout_gallery_gallery’));
    or using a subfield
    count(get_subfield(‘gallery’));
    or
    count(get_subfield(‘layout_gallery_gallery’));

    unfortunately none of this returns the correct number of photos in the gallery.

    Could someone advise me what I’m doing wrong?
    Thank you very much.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.