Right now I have this inside of a channel entries tag.

{exp:query sql="SELECT total_entries FROM exp_channels WHERE channel_name = '{url_title}'"} 

Which provides me with the correct count as expected. (E.g. 8)

But say only 5 of those 8 are of the status I want to count. How can I have it only count those entries? Let's say the status is "featured" or "open"? I feel this is not the correct method.

Thank you!

3 Answers 3


It might work out easier to turn this into a short plugin, but would a query like this work? You'd need to pass in the id of the channel you're looking for.

{exp:query sql="SELECT count(*) AS totaled FROM exp_channel_titles WHERE channel_id='{channel_id}' AND status='open'"}
  • Very close, but because I'm working within Structure, I have to use channel_name instead of channel_id. (wonky I know) Would probably work for anyone else. Commented Dec 20, 2016 at 21:43

So... I finally got it working, though not with SQL which I imagine is more efficient. Behold my mess. Note this is only because I'm having to nest it, and also match to url_title because of how we use Structure Listings. Appreciate the help.

{exp:vmg_nested:channel:entries channel="{url_title}" dynamic="off" status="available" prefix="childlisting"}
{if 1 == '{childlisting:count}'}{childlisting:absolute_results}{/if}

Used plugin: https://devot-ee.com/add-ons/vmg-nested

  • Good find, glad you solved it! Commented Dec 20, 2016 at 21:49

exp_channels is a table that contains summary information about the channels defined within your EE MySQL database, and one of the fields it contains is total_entries - so all your sql query is doing is picking that value from the table. You could get the same information with a bit less complication by using the statistics module within EE. Something like:

{exp:stats channel = '{url_title}'}

To get information on the status of entries within the channel, you'd need to run a query on the channel data itself (which is stored in the table exp_channel_titles). This would require a more complicated sql query, but you could also do it using a regular exp:channel:entries call such as:

{exp:channel:entries channel="{url_title}" status="{status}"}


  • Thanks. Yeah stats unfortunately is very limited in ability. I have something like the channel entries option here working, but it repeats the total_results multiple times and in my case, if count == 1 doesn't apply to me because I'm having to nest tags, difficult to explain. But it's why I basically have to go with a query. Commented Dec 20, 2016 at 21:00
  • Not sure the 'limited ability' of stats is an issue - as your original sql is not doing anything special, just pulling the value of a field which you could do some other way. The issue with counting entries with specific characteristics (e.g. status) is that you actually have to count them somehow - which makes you end up with more complex structures. A sql query is fine, but there might be other ways too. Commented Dec 20, 2016 at 21:46

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.