Take the 2-minute tour ×

Is this the most efficient way to filter a load of channel entries? I want to display entries that have no comments and that are not sticky. I'm using this code.

{exp:channel:entries channel="{segment_3}" status="open" orderby="date" disable="categories|category_fields|member_data|pagination"}

  {if comment_total == "0" AND sticky == 'n'}


Cheers Lee

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Using conditional variables, probably. But this will likely return lots more results than you need. Plus you won't be able to accurately use {count} (maybe not an issue for you, though).

Another approach which doesn't use conditional variables, but just goes straight after the results you want, and only the results you want, is to use the Query Module

{exp:query sql=
    "SELECT title
    FROM exp_channels
    JOIN exp_channel_titles ON exp_channels.channel_id = exp_channel_titles.channel_id
    WHERE exp_channels.channel_name = '{segment_3}'
    AND exp_channel_titles.status = 'open'
    AND exp_channel_titles.sticky = 'n'
    AND exp_channel_titles.comment_total = 0"

This could get tedious if you needed to access a bunch of custom fields, but it is an efficient way to get the results you want.

share|improve this answer

Sticky is an available parameter on the entries loop, so you could filter at least that element in the entries loop itself by simply adding sticky="no", but comments, unfortunately, is not an available parameter, so Alex's suggestion may be the best option if your requirements are fairly simple. If you need access to a significant number of custom fields, however, it may be a bit tricky. So you'll have to decide what approach to take based on what you need within your loop.

share|improve this answer
Does the sticky="no" parameter not show sticky entries? Or does it show them, but in their normal position (not stuck at the top)? I can't remember but I think it is the latter. –  Alex Kendrick Nov 11 '12 at 17:05
Just checked, and the sticky="no" parameter will still return sticky entries, just in their regular place in the results. –  Alex Kendrick Nov 11 '12 at 17:10
Nuts. Yeah that figures. I hadn't thought about that. It's just disabling the "sticky" function, not removing items so marked. I use status instead of sticky for various reasons - this is now another! –  Jean St-Amand Nov 12 '12 at 17:54

Your Answer


