I am currently trying to count all ACF repeater fields that belong to the determined post type.
Post type: investors
ACF Repeater Field: suchprofile
Somehow I do not get any further. Or rather I get a value of 0.
Is this because a loop is missing? I just want to count everything. For example, if a 20 investors (post type) each have 20 suchprofil (acf reapeater field) I want to output 400.
function suchprofile_shortcode( $atts ) {
$rows = get_sub_field('suchprofil');
if( have_rows('suchprofil') );
$count = count($rows);
echo $count;
}
add_shortcode( 'suchprofile', 'suchprofile_shortcode');
Does anyone have an idea. Tried various posts and solutions.
Best thanks
Andy
In order to do this you would need to
- Do a WP_Query() to get all of the posts
- Loop over the posts
- use get_post_meta() on the repeater instead of get_field(), this will return the count of rows for the repeater rather than the field contents.
- Add the returned values.