Home › Forums › Add-ons › Repeater Field › Sum Repeater fields › Reply To: Sum Repeater fields
Thanks John, Allison.
Unfortunately they didn’t do the trick. It might help if I reword my question with a real example.
I’m trying to make a table that shows the total number of products shipped across all shipments.
Shipment ‘123’ has the following products:
Baseball Cap * 1
T-Shirt * 2
‘Shipment’ is my CPT and my subfields within the ‘products’ repeater are ‘product_name’ and ‘product_quantity’.
John’s code seems like it would take the total quantity of ALL products shipped, not the quantity of each particular product.
$total_items = 0;
if (have_rows('shipment')) {
while (have_rows('shipment')) {
$total_items += get_sub_field('product_quantity');
}
}
echo $total_items;
Allison’s code seems like it should work but doesn’t refer to the ‘shipments’ CPT, so I’m not sure how it knows where to look for the ‘products’ repeater fields.
Thanks for the help anyway!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.