we need a 'counter' which displays the total number of entries for a given channel limited by category and status.

Were originally doing this via the EE Stats module before the Status/Cats requirement was added, the Stats module can't handle those parameters so need another approach - we're talking about possibly 10k entries so we can;t sure 'count' - it's going to have to be a query or a plugin.

Does anyone have any suggestions for that sort of large amount? Thanks!

1 Answer 1


The query module would do nicely here. Unless the information rapidly changes and 100% accuracy is necessary, I also recommend tag caching if the page itself is not cached.

{exp:query sql="SELECT COUNT(*) AS total
    FROM exp_channel_titles t
    WHERE t.channel_id = 1
    AND t.status IN ('open', 'featured')
    AND t.entry_id IN (SELECT entry_id FROM exp_category_posts WHERE cat_id = 265)"
    cache="yes" refresh="43200"}
        There are {total} entries in Channel ID 1 with a Category ID of 265.

You can of course change the channel_id and cat_id as necessary.

  • 1
    Cheers, Derek. The info probably changes daily but only on a mass 'approval' of entries by Admins so I think the caching is fine. Is there any way to add the status to this query to filter but this too?
    – segovius
    May 21, 2014 at 7:40
  • Absolutely, I've updated the answer to include status filtering. May 21, 2014 at 15:35
  • 1
    @segovius Disallowed Key Characters has to do with input - are you getting this error when you try to add it to a Snippet or Template? If so, it sounds like your browser or host is adding something to the request, as this data in your template wouldn't have anything to do with GET keys in the page request. Jul 1, 2014 at 21:22
  • 1
    Check with your host, it sounds like there may be some server-side security software (mod_security for example) that is not happy with that data being POSTed, and is perhaps redirecting or changing the request to an invalid URL. What URL is in your address bar when you receive that error? Also, you can edit /system/codeigniter/system/core/Input.php around line 731 to: exit('Disallowed Key Characters: '.htmlentities($str)); which will output the "naughty" input key. Jul 2, 2014 at 14:58
  • 1
    You should be using the {total} variable that the query is creating. {total_results} is the number of rows returned (always 1 with this query), and {total_entries} is a global variable referring to your site's statistics. Jul 15, 2014 at 21:39

Your Answer

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

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