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
?
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' />