4

I have a very strange issue. When using the first EE channel:entries code my no_results tag works, but when using the exact same channel:entries tag together with the category="" parameter the no_results tag doesn't work. Any ideas?

The {last_segment_category_id} variable being empty, of course.

Works:

{exp:channel:entries channel="channel_name" dynamic="no" disable="pagination|member_data"}
{if no_results}
<i>No results...</i>
{/if}
{/exp:channel:entries}

Doesn't work:

{exp:channel:entries channel="channel_name" category="{last_segment_category_id}" dynamic="no" disable="pagination|member_data"}
{if no_results}
<i>No results...</i>
{/if}
{/exp:channel:entries}
  • Have you tried adding the require_entry="yes" parameter? The issue is it's picking up something in the category parameter due to {last_segment_category_id}. What happens if you hard code a category id? – Peter Lewis May 9 '14 at 15:52
  • The require_entry="yes" didn't change anything and if I hard-code an category_id="123" that doesn't exist there's no entries in the loop but the no_results tag doesn't work either. It doesn't output any entries, but it doesn't recognize there's no result either? – naboovalley May 11 '14 at 16:19
  • Did you figure out the answer? i'm having the same thing here. – Visual Jun 12 '14 at 11:49
  • No. I believe this is as excepted by the tag I'm afraid. I would consider this a bug but I don't know :) – naboovalley Jun 13 '14 at 14:03
  • 1
    Submit this as a bug: support.ellislab.com/bugs – Romans-8---31-39 Aug 1 '14 at 14:42
1

Here is a work around you can do to get the same desired results:

{exp:query limit="1 sql="SELECT entry_id FROM `exp_category_posts` WHERE cat_id = '{last_segment_category_id}"}
    {exp:channel:entries channel="channel_name" category="{last_segment_category_id}" dynamic="no" disable="pagination|member_data"}
       <h1>Title</h1>
    {/exp:channel:entries}
    {if no_results}
       No Results....
    {/if}
{/exp:query}

What i'm doing here is querying the database to check to see if any entry_ids exist connected to a given category. If so, it will parse the expression engine tags, if not it will display the exp:query no results content.

Hope this helps.

| improve this answer | |
1

This has been reported to EllisLab as a bug. It is not working as it should. https://support.ellislab.com/bugs/detail/21106

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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