0

We are a non-profit organization with many volunteers that we assign to various volunteer roles. I created a Volunteers channel and a Roles channel, and in the Roles channel I set up a relationship field called role_membership where I can add all of the volunteers in the role. So, I might have a role titled Website Developer, and select John Doe and Jane Smith in the role_membership field. In this way, many volunteers will be assigned to roles, but we also have new volunteers that have not been assigned a role yet.

What I want to do is to count the number of entries in the Volunteers channel that have been associated with at least one role (i.e., that have a parent in the Roles channel, role_membership field). I can't figure out how to alter the exp:channel:entries tag to get this count directly. Instead I've tried using PHP, but that is not working well. The following code will work IF I use limit="50" to set a low limit on the number of channel entries returned. But, if I set limit="2000" to get the count I need, I get a PHP out of memory error.

<?php $assigned_volunteers=0; ?> {exp:channel:entries channel="volunteers" limit="50"} {parents field="role_membership"} {if {parents:total_results}>0}<?php $assigned_volunteers+=1; ?>{/if} {/parents} {/exp:channel:entries}

Is there a way to obtain the count of volunteers assigned to roles directly by altering the exp:channel:entries tag?

  • Is this data you are trying to get for personal use, or to actually display it on the front end? – Justin Clarke Jul 23 '14 at 15:25
  • I want to display it on the front end, but if that is difficult or impossible, I would settle for getting the data for personal use. – ChristinaB Jul 24 '14 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.