Show total number of results outside of loop

I am trying to display the total number of results found in a loop (there should be 2).

I tried this and it just returned ‘1’

<Loop type=inventory field=inventoryitem_status field_value="In Stock">
<Get loop=total />

I then tried this, and allow if gave the correct total it showed it for the same number of results in loop (so twice in my example)

<Loop type=inventory field=inventoryitem_status field_value="In Stock">
<Get loop=total />

It’s probably really obvious what I am doing wrong - but any guidance would be great.


Hi Chris!

<Get loop=total /> only works within the context of a loop and would be useful if you wanted to do something like Item <Get loop=count /> of <Get loop=total /> on each item in your loop.

The correct variable, which gets the “Total number of items in previous loop, after it’s closed”, is: <Get loop=previous_total />

Here’s the documentation for our loop variables

1 Like

Hi Julia

I am using the variable and it works, I have however come across a situation where if their is no results in the loop, instead of showing 0 it shows the previous loops total (where they are on the same page)

Any ideas how I can have it display 0?



Hi Chris, that sounds like a bug in how the previous loop total is calculated. I took a quick look at the code but the logic there seems to be fine. I’ll set up a test case to see if I can recreate the issue and figure out what’s happening.


Hi Chris, the issue has been solved in the newest plugin version:

  • Loop tag: Ensure previous total is correctly set to 0 if last loop had no items