ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Get count of entries with certain status

January 19, 2012 8:49am

Subscribe [4]
  • #1 / Jan 19, 2012 8:49am

    MadeByShape

    35 posts

    Im trying to get a total count of entries, that all have the same Status as Processing.

    But when i use the {total_results} variable, it repeats the number 3 times, if i have 3 entries with Status of Processing?

    Here’s my code:

    <div class="success">
    You have {exp:channel:entries channel="{channels}" status="Processing"}{total_results}{/exp:channel:entries} new order(s)
    </div>

    I thought {total_results} just displayed once in a loop?

  • #2 / Jan 19, 2012 10:01am

    Philip Zaengle

    293 posts

    This is really inefficient query wise, but you could use what you have and just add

    {if count == 1}{total_results}{/if}

    You could also write your own query with the query module which would be far more optimized - or use something like this: http://devot-ee.com/add-ons/entries-number (albeit overpriced).

  • #3 / Jan 19, 2012 10:08am

    Philip Zaengle

    293 posts

    They query would look something like this:

    {exp:query sql="
     SELECT 
      COUNT(entry_id) AS total_entry_count
     FROM
      exp_channel_titles
     WHERE
      channel_id = 1 AND status = 'open'
    "} 
    
     {total_entry_count}
     
    {/exp:query}
  • #4 / Jan 19, 2012 10:29am

    MadeByShape

    35 posts

    Magic, thanks. Yeah i was going to write a Query, but just wondered if there was a way with the channel entries.

  • #5 / Jan 20, 2012 2:51pm

    Dan Decker

    7338 posts

    Hey Shape.,

    Looks like you are all set here? Is there anything else we can assist you with?

    Cheers!

  • #6 / Mar 15, 2012 4:07am

    Marc Tiedemann

    119 posts

    Excellent just what I needed right now, too. 😊 Thanks Philip!

  • #7 / Mar 16, 2012 2:52pm

    Kyle Cotter

    730 posts

    Glad Philip was able to help everyone out here.

    If anyone has any more questions, feel free to start a new thread.

    Thanks!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases