## Support

### Account

Home Forums Front-end Issues Calculate sub field rows

Solving

# Calculate sub field rows

• Hey Guys,

Struggling to get my head around this one, and i may have to tackle this a different way if it isnt possible.

I have a CPT which has a repeater field, which contains a Post Object, Weight, Price columns.

Post Object is a CPT with different types of materials (metal/wood etc)

Each post created can obviously have multiple rows in the repeater, with different Post Objects on each row.

Is there any way possible, to calculate all the Weight or Cost rows together, but just for ALL Post Objects posted within a defined date range.

EG:
Post 1:
Wood | 10KG | £3
Metal | 1kg | £1

Post 2:
Metal | 3kg | £1
Paper | 10kg | £3
Wood | 2kg | £3

Reporting Page Output (between date range):
Wood | 12KG | £6
Metal | 4KG | £2
Paper | 10kg | £3

Hopefully the above makes sense to somebody, and somebody can help shed some light on how to filter and calculate this data.

Thanks!

• Not sure what you’re trying to total here. The values in the repeater or the values in the repeater of the related post object field in the repeater.

• Hi, sorry for not being clear, i think i spent way too long staring at the screen that day.

I would need to be able to calculate all the rows which have the same Post Object together.

So if 5 separate posts have a repeater field and post object field of Wood.

I would need a reporting page, to calculate all the Wood row values together.

• On the page template for the post with the post objects you need to loop through the repeater, get the post object and then loop though the fields of the related post.

``````
if (have_rows('repeater_name')) {
while('have_rows'('repeater_name')) {
the_row();
\$post_object = get_sub_field('post_object_field');
// now we get the values from the other post
if (have_rows('repeater_name', \$post_object->ID)) {
have_rows('repeater_name', \$post_object->ID)) {
the_row();
// get sub field values needed
// and add them to something
}
}
}
}
``````
• On the actual post object itself, there isnt any data to be pulled out, its simply a drop down of different typed of materials.

Where i posted the example further up of the calculation i wished to try create, they would have all been repeater fields in separate posts sorted by:
Post Object | Weight | Cost

So the ideal calculation would be across posts between X and Y date range, add all rows/columns with duplicate Post Objects across all posts together. Creating a Total Weight and a Total Cost attached to that Post Type.

• What is it that you want to get from the post object then?

• Nothing is needed from within the post object for this reporting section.

• So then you only need the nested loop to get and display the values needed from there and you’d do your calculation in the first loop.

``````
if (have_rows('repeater_name')) {
while('have_rows'('repeater_name')) {
the_row();
\$post_object = get_sub_field('post_object_field');
// get other field of row
// store to do calculation later
// or do it now
}
}
``````
• I think he is trying to pulls the repeater row values == to wood, paper, etc from all different associated posts.

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Calculate sub field rows’ is closed to new replies.