0

I'm wondering if it is possible to show a count of entries with a custom field value.

For example if I have a channel with a custom field that can have a value of either "Y" or "N".

When I show a list of entries in that channel I can easily show the total number of entries, but how would I show the total number of entries along with the total number of entries with my custom field set to "N" and the total number of entries with my custom field set to "Y"?

Something like: All Entries = 12, Y Entries = 4, N Entries = 8

Thanks!

1 Answer 1

0

http://ee2docs.com/add-ons/channel/channel_entries.html#search-field-name

Something like:

{exp:channel:entries
    channel="my_channel"
    search:my_field="Y"}

    {absolute_results}

{/exp:channel:entries}

Should do it. That should give you the total count of entries with your my_field field set to "Y". Just omit the search param to get all results; you may have to put a very high limit param if you have more than 100 entries as the Channel Entries tag defaults to a limit of 100. If that doesn't work for you, I can craft up a quick {exp:query} tag for you that will do that trick.

2
  • Unfortunately that doesn't work. The code above outputs the {absolute_results} count as many times as there are entries that match, so if I have 60 entries that match it prints 60, 60 times... If I set limit="1" then {absolute_results} returns 1 once.
    – Bryan
    Nov 19, 2015 at 19:24
  • Nevermind, if I wrap {absolute_results} in an {if count == 1} conditional it does the trick. Seems like this might be a little heavy on the template parser but I guess it'll have to do.
    – Bryan
    Nov 19, 2015 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.