Skip Navigation

[Resolved] Display number of items in multiple-instances custom field

This support ticket is created 4 years, 3 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 andrei-laurentiuP 4 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1450347

I am displaying a multi-instance image custom field using wpv-for-each.

I only render the first couple of images (e.g. first 3) and then I want to display a link with "+[NUMBER OF IMAGES]" remaining.

[wpv-for-each field="wpcf-images" start="4"]
<a data-lightbox="images" href="[types field="images" raw="true"][/types]"> +[NUMBER OF IMAGES]
</a>
[/wpv-for-each]

I would like to know how I may display the "+[NUMBER OF IMAGES]".

Is there a direct attribute to do that or how may I do it?

Thanks

#1450965

Nigel
Supporter

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

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

Hi Andrei

I'm not sure what you intend to link to.

You can register a shortcode which will display how many instances of the field there are for example, or a shortcode to display the current instance as an index, so that you could display something like "2 of 6", for example.

Here are shortcodes that would do those:

add_shortcode('wpv-instances', function ($atts = []) {

    // provide defaults
    $atts = shortcode_atts(
        array(
            'field' => '',
        ),
        $atts
    );

    if ( isset( $atts['field'] ) ){
        global $post;
        $values = get_post_meta( $post->ID, $atts['field'], false );
        $count = count( $values );

        return $count;
    }

});

add_shortcode('wpv-index', function () {

    static $i = 1;
    $n = $i++;
    
    return $n;
});

You when use them inside a wpv-for-each loop like so:

[wpv-for-each field='wpcf-telefono']
<p>[types field='telefono'][/types] ([wpv-index] of [wpv-instances field='wpcf-telefono'])</p>
[/wpv-for-each]

But I don't really understand the request about linking to something.

#1458413

My issue is resolved now. Thank you!

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