Skip Navigation

[Resolved] Get Count of Multiple Instance Fields

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 9 years, 3 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 – 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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by scottD-2 9 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#276105

I am trying to: Count the number of times a multiple-instance field has been used. For example, I am using a multiple-instance field to enter songs/tracks on an album. I would like to be able to display the number of tracks on each album in the content template.

Specifically, the reason for this is I am attempting to use the Schema.org markup for Music Album, which asks for the number of tracks. hidden link

For example:

<meta content="8" itemprop="numTracks" />

Would there be a way to count the number of the multiple-instance field I'm using for tracks on the album to fill in the

content="8"

?

#276207

You can try create a custom shortcode for it, for example another similar thread:
https://toolset.com/forums/topic/show-count-of-repeating-field-entries/#post-106826

#276379

That solution works for me!

In case anyone else stumbles upon this thread, the final solution was to create a shortcode in a plugin like this:

//Shortcode to display number of tracks on an album
add_shortcode( 'count-tracks', 'count_tracks_func' );
function count_tracks_func($atts) {
    return sizeof(get_post_meta( get_the_ID(), 'wpcf-' . $atts['field'], false));
}

Then in the Content Template for the album, I was able to use this shortcode to display the number of tracks on the album:

[count-tracks field="track-listing"]

This can then be used with the schema markup for MusicAlbum like this:

<meta content='[count-tracks field="track-listing"]' itemprop='numTracks' />

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.