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.

Strictly exclude categories?

December 14, 2012 1:38pm

Subscribe [3]
  • #1 / Dec 14, 2012 1:38pm

    The Adsmith

    4 posts

    I was wondering if there is any native way to strictly exclude categories.

    In other words, I currently have the setup:

    {exp:channel:entries channel="attractions" category="not 24" dynamic="no"}
         [data here]
    {/exp:channel:entries}

    This is a problem because some of my entries are categorized in multiple categories such as 24 and 26 etc. I’d really like to exclude any entry categorized as 24 regardless of wether or not it is also in another category.

    I realize I can use the query module to write a custom query to do this, but I was hoping there is some “more native” solution… maybe a parameter or setting I overlooked in the documentation.

    Has anyone had any success with this? Or do I need to write a custom query?

  • #2 / Dec 17, 2012 3:53pm

    MadWebDesigns

    147 posts

    I don’t think so. This is to complex to do with EE channel entries tag. You will have to use the query tag.

    Mike

  • #3 / Dec 17, 2012 5:07pm

    The Adsmith

    4 posts

    Thanks for the reply. I was afraid that might be the case. :(


    After playing around a bit more, I managed a result that is more or less similar.

    I separated the categories into two groups and limited the filter to a particular group. So:

    {exp:channel:entries channel="attractions"  dynamic="no" category_group="1" category="not 24"}
    
        [data]
    
    {/exp:channel:entries}

    Obviously this still breaks down if the entry is categorized as more than one category in a group, but it works OK, and at least I didn’t have to write a complex custom query. B)

  • #4 / Dec 17, 2012 5:23pm

    GDmac - expocom

    350 posts

    A workaround “might be” to set the category with a custom fieldtype (instead of regular categories) the search:fieldname=”=not 24” might enable more strict selection.

    ps. i had a feature request for more strict category control in the old forums, here’s the query solution to select entries with “only” category 4, using “regular” category assignment:

    // main template
    {embed="test/unique_category" entries='{exp:query sql="
      SELECT entry_id 
      FROM exp_category_posts
      WHERE cat_id= 4 AND entry_id NOT IN(
        SELECT entry_id FROM exp_category_posts WHERE cat_id != 4
      )
    "}{entry_id}|{/exp:query}'}
    
    // embedded template
    {if embed:entries==""}
      not found
    {/if}
    // if:else would cause it to be an advanced conditional
    {if embed:entries!=""}
      {exp:channel:entries entry_id="{embed:entries}"}
        {title}
      {/exp:channel:entries}
    {/if} 
  • #5 / Dec 18, 2012 2:11pm

    The Adsmith

    4 posts

    Thanks for the query! That would have taken me quite a bit to work out on my own. :D

    I think in this case I have enough control over the data entry to leave my original “lenient” solution. However, it’s good to know I can switch it out for a more solid solution if it begins to cause issues in the future.

    I had considered the custom field as well, but I felt it was a little strange to ask users to “categorize it twice.” :/
    I see how that could work well though.

    Well, no “perfect” native solutions, but certainly enough to make something work.

    Thanks again for the help.

    ~Kara

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

ExpressionEngine News!

#eecms, #events, #releases